34 return QObject::tr(
"Standard Deviation" );
44 auto c = std::make_unique< QgsClassificationStandardDeviation >();
56QList<double> QgsClassificationStandardDeviation::calculateBreaks(
double &minimum,
double &maximum,
57 const QList<double> &values,
int nclasses, QString &error )
68 if ( values.isEmpty() )
69 return QList<double>();
73 const int n = values.count();
75 for (
int i = 0; i < n; i++ )
79 mean = mean /
static_cast< double >( n );
82 for (
int i = 0; i < n; i++ )
84 sd = values[i] - mean;
87 mStdDev = std::sqrt( mStdDev / n );
92 QList<double> breaks =
QgsSymbolLayerUtils::prettyBreaks( ( minimum - mEffectiveSymmetryPoint ) / mStdDev, ( maximum - mEffectiveSymmetryPoint ) / mStdDev, nclasses );
95 for (
int i = 0; i < breaks.count(); i++ )
96 breaks[i] = ( breaks[i] * mStdDev ) + mEffectiveSymmetryPoint;
103 const QString lowerLabel = valueToLabel( lowerValue );
104 const QString upperLabel = valueToLabel( upperValue );
109 return QStringLiteral(
"< %1" ).arg( upperLabel );
113 label.replace( QLatin1String(
"%1" ), lowerLabel ).replace( QLatin1String(
"%2" ), upperLabel );
117 return QStringLiteral(
"≥ %1" ).arg( lowerLabel );
123QString QgsClassificationStandardDeviation::valueToLabel(
const double value )
const
125 const double normalized = ( value - mEffectiveSymmetryPoint ) / mStdDev;
126 return QObject::tr(
" %1 Std Dev" ).arg( QLocale().toString( normalized,
'f', 2 ) );
134 element.setAttribute( QStringLiteral(
"std_dev" ), QString::number( mStdDev,
'f', 16 ) );
135 element.setAttribute( QStringLiteral(
"effective_symmetry_point" ), QString::number( mEffectiveSymmetryPoint,
'f', 16 ) );
142 mStdDev = element.attribute( QStringLiteral(
"std_dev" ), QStringLiteral(
"1.0" ) ).toDouble();
143 mEffectiveSymmetryPoint = element.attribute( QStringLiteral(
"effective_symmetry_point" ), QStringLiteral(
"0.0" ) ).toDouble();
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
double symmetryPoint() const
Returns the symmetry point for symmetric mode.
bool symmetricModeEnabled() const
Returns if the symmetric mode is enabled.
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...
ClassPosition
Defines the class position.
@ LowerBound
The class is at the lower bound.
@ UpperBound
The class is at the upper bound.
@ Inner
The class is not at a bound.
bool symmetryAstride() const
Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the...
QString labelFormat() const
Returns the format of the label for the classes.
QgsClassificationMethod(MethodProperties properties=NoFlag, int codeComplexity=1)
Creates a classification method.
@ SymmetricModeAvailable
This allows using symmetric classification.
void copyBase(QgsClassificationMethod *c) const
Copy the parameters (shall be used in clone implementation).
QIcon icon() const override
The icon of the method.
QString name() const override
The readable and translate name of the method.
QgsClassificationStandardDeviation()
static const QString METHOD_ID
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const override
Writes extra information about the method.
QString labelForRange(double lowerValue, double upperValue, ClassPosition position) const override
Returns the label for a range.
QString id() const override
The id of the method as saved in the project, must be unique in registry.
void readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads extra information to apply it to the method.
std::unique_ptr< QgsClassificationMethod > clone() const override
Returns a clone of the method.
A container for the context for various read/write operations on objects.
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...
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