33 return QObject::tr(
"Standard Deviation" );
55 QList<double> QgsClassificationStandardDeviation::calculateBreaks(
double minimum,
double maximum,
56 const QList<double> &values,
int nclasses )
66 if ( values.isEmpty() )
67 return QList<double>();
71 int n = values.count();
73 for (
int i = 0; i < n; i++ )
77 mean = mean /
static_cast< double >( n );
80 for (
int i = 0; i < n; i++ )
82 sd = values[i] - mean;
85 mStdDev = std::sqrt( mStdDev / n );
90 QList<double> breaks =
QgsSymbolLayerUtils::prettyBreaks( ( minimum - mEffectiveSymmetryPoint ) / mStdDev, ( maximum - mEffectiveSymmetryPoint ) / mStdDev, nclasses );
93 for (
int i = 0; i < breaks.count(); i++ )
94 breaks[i] = ( breaks[i] * mStdDev ) + mEffectiveSymmetryPoint;
101 const QString lowerLabel = valueToLabel( lowerValue );
102 const QString upperLabel = valueToLabel( upperValue );
107 return QStringLiteral(
"< %1" ).arg( upperLabel );
111 label.replace( QLatin1String(
"%1" ), lowerLabel ).replace( QLatin1String(
"%2" ), upperLabel );
115 return QStringLiteral(
"≥ %1" ).arg( lowerLabel );
121 QString QgsClassificationStandardDeviation::valueToLabel(
const double value )
const 123 double normalized = ( value - mEffectiveSymmetryPoint ) / mStdDev;
124 return QObject::tr(
" %1 Std Dev" ).arg( QString::number( normalized,
'f', 2 ) );
132 element.setAttribute( QStringLiteral(
"std_dev" ), QString::number( mStdDev,
'f', 16 ) );
133 element.setAttribute( QStringLiteral(
"effective_symmetry_point" ), QString::number( mEffectiveSymmetryPoint,
'f', 16 ) );
140 mStdDev = element.attribute( QStringLiteral(
"std_dev" ), QStringLiteral(
"1.0" ) ).toDouble();
141 mEffectiveSymmetryPoint = element.attribute( QStringLiteral(
"effective_symmetry_point" ), QStringLiteral(
"0.0" ) ).toDouble();
The class is used as a container of context for various read/write operations on other objects...
QString id() const override
The id of the method as saved in the project, must be unique in registry.
bool symmetryAstride() const
Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the...
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
The class is not at a bound.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
The class is at the upper bound.
The class is at the lower bound.
double symmetryPoint() const
Returns the symmetry point for symmetric mode.
QString labelForRange(double lowerValue, double upperValue, ClassPosition position) const override
Returns the label for a range.
static const QString METHOD_ID
void copyBase(QgsClassificationMethod *c) const
Copy the parameters (shall be used in clone implementation)
bool symmetricModeEnabled() const
Returns if the symmetric mode is enabled.
QString labelFormat() const
Returns the format of the label for the classes.
void readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads extra information to apply it to the method.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const override
Writes extra information about the method.
QgsClassificationCustom is an implementation of QgsClassificationMethod based on standard deviation...
ClassPosition
Defines the class position.
QgsClassificationStandardDeviation()
static void makeBreaksSymmetric(QList< double > &breaks, double symmetryPoint, bool astride)
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically bala...
QIcon icon() const override
The icon of the method.
QgsClassificationMethod * clone() const override
Returns a clone of the method.
QString name() const override
The readable and translate name of the method.
QgsClassificationMethod is an abstract class for implementations of classification methods...