QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsclassificationmethod.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsclassificationmethod.h
3 ---------------------
4 begin : September 2019
5 copyright : (C) 2019 by Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSCLASSIFICATIONMETHOD_H
17#define QGSCLASSIFICATIONMETHOD_H
18
19#include <QIcon>
20
21#include "qgis_sip.h"
22#include "qgis_core.h"
24
25class QgsVectorLayer;
27
28
29#ifdef SIP_RUN
30// This is required for the ConvertToSubClassCode to work properly
31// so RTTI for casting is available in the whole module.
32% ModuleCode
39% End
40#endif
41
42
43
49class CORE_EXPORT QgsClassificationRange
50{
51 public:
53 QgsClassificationRange( const QString &label, double lowerBound, double upperBound )
54 : mLabel( label )
55 , mLowerBound( lowerBound )
56 , mUpperBound( upperBound )
57 {}
59 double lowerBound() const {return mLowerBound;}
61 double upperBound() const {return mUpperBound;}
62
64 QString label() const {return mLabel;}
65
66#ifdef SIP_RUN
67 SIP_PYOBJECT __repr__();
68 % MethodCode
69 QString str = QStringLiteral( "<QgsClassificationRange: '%1'>" ).arg( sipCpp->label() );
70 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
71 % End
72#endif
73
74 private:
75 QString mLabel;
76 double mLowerBound;
77 double mUpperBound;
78};
79
80
81
89{
90
91#ifdef SIP_RUN
93 if ( dynamic_cast<QgsClassificationEqualInterval *>( sipCpp ) )
94 sipType = sipType_QgsClassificationEqualInterval;
95 else if ( dynamic_cast<QgsClassificationJenks *>( sipCpp ) )
96 sipType = sipType_QgsClassificationJenks;
97 else if ( dynamic_cast<QgsClassificationPrettyBreaks *>( sipCpp ) )
98 sipType = sipType_QgsClassificationPrettyBreaks;
99 else if ( dynamic_cast<QgsClassificationQuantile *>( sipCpp ) )
100 sipType = sipType_QgsClassificationQuantile;
101 else if ( dynamic_cast<QgsClassificationStandardDeviation *>( sipCpp ) )
102 sipType = sipType_QgsClassificationStandardDeviation;
103 else if ( dynamic_cast<QgsClassificationFixedInterval *>( sipCpp ) )
104 sipType = sipType_QgsClassificationFixedInterval;
105 else
106 sipType = 0;
107 SIP_END
108#endif
109
110 public:
111
114 {
115 NoFlag = 0,
116 ValuesNotRequired = 1 << 1,
117 SymmetricModeAvailable = 1 << 2,
118 IgnoresClassCount = 1 << 3,
119 };
121
122
123
125 {
128 UpperBound
129 };
130
136 explicit QgsClassificationMethod( MethodProperties properties = NoFlag, int codeComplexity = 1 );
137
138 virtual ~QgsClassificationMethod();
139
145
147 virtual QString name() const = 0;
148
150 virtual QString id() const = 0;
151
153 virtual QIcon icon() const {return QIcon();}
154
161
165 virtual QString labelForRange( double lowerValue, double upperValue, ClassPosition position = Inner ) const;
166
167
169 virtual void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const {Q_UNUSED( element ); Q_UNUSED( context )}
171 virtual void readXml( const QDomElement &element, const QgsReadWriteContext &context ) {Q_UNUSED( element ); Q_UNUSED( context )}
172
177 virtual bool valuesRequired() const {return true;}
178
179
180 // *******************
181 // non-virtual methods
182
184 int codeComplexity() const {return mCodeComplexity;}
185
189 bool symmetricModeAvailable() const {return mFlags.testFlag( SymmetricModeAvailable );}
190
194 bool symmetricModeEnabled() const {return symmetricModeAvailable() && mSymmetricEnabled;}
195
199 double symmetryPoint() const {return mSymmetryPoint;}
200
205 bool symmetryAstride() const {return mSymmetryAstride;}
206
214 void setSymmetricMode( bool enabled, double symmetryPoint = 0, bool symmetryAstride = false );
215
216 // Label properties
218 QString labelFormat() const { return mLabelFormat; }
220 void setLabelFormat( const QString &format ) { mLabelFormat = format; }
222 int labelPrecision() const { return mLabelPrecision; }
224 void setLabelPrecision( int labelPrecision );
226 bool labelTrimTrailingZeroes() const { return mLabelTrimTrailingZeroes; }
228 void setLabelTrimTrailingZeroes( bool trimTrailingZeroes ) { mLabelTrimTrailingZeroes = trimTrailingZeroes; }
229
231 static QList<double> rangesToBreaks( const QList<QgsClassificationRange> &classes );
232
241 Q_DECL_DEPRECATED QList<QgsClassificationRange> classes( const QgsVectorLayer *layer, const QString &expression, int nclasses ) SIP_DEPRECATED;
242
255 QList<QgsClassificationRange> classesV2( const QgsVectorLayer *layer, const QString &expression, int nclasses, QString &error SIP_OUT );
256
262 QList<QgsClassificationRange> classes( const QList<double> &values, int nclasses );
263
271 QList<QgsClassificationRange> classes( double minimum, double maximum, int nclasses );
272
278 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;
279
285 static QgsClassificationMethod *create( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
286
294 static void makeBreaksSymmetric( QList<double> &breaks SIP_INOUT, double symmetryPoint, bool astride );
295
299 QString labelForRange( const QgsRendererRange &range, ClassPosition position = Inner ) const;
300
305 const QgsProcessingParameterDefinition *parameterDefinition( const QString &parameterName ) const;
306
312
317 void setParameterValues( const QVariantMap &values );
318
324 QVariantMap parameterValues() const {return mParameterValues;}
325
326 static const int MAX_PRECISION;
327 static const int MIN_PRECISION;
328
329 protected:
330
332 void copyBase( QgsClassificationMethod *c ) const;
333
335 QString formatNumber( double value ) const;
336
344 void addParameter( QgsProcessingParameterDefinition *definition SIP_TRANSFER );
345
346 private:
347
353 virtual QList<double> calculateBreaks( double &minimum, double &maximum,
354 const QList<double> &values, int nclasses, QString &error ) = 0;
355
357 virtual QString valueToLabel( double value ) const {return formatNumber( value );}
358
360 QList<QgsClassificationRange> breaksToClasses( const QList<double> &breaks ) const;
361
362 // implementation properties (set by initialization)
363 MethodProperties mFlags = MethodProperties();
364 int mCodeComplexity = 1;
365
366 // parameters (set by setters)
367 // if some are added here, they should be handled in the clone method
368 bool mSymmetricEnabled = false;
369 double mSymmetryPoint = 0;
370 bool mSymmetryAstride = false;
371 int mLabelPrecision = 4;
372 bool mLabelTrimTrailingZeroes = true;
373 QString mLabelFormat;
374
375 // values used to manage number formatting - precision and trailing zeroes
376 double mLabelNumberScale = 1.0;
377 QString mLabelNumberSuffix;
378
381 QVariantMap mParameterValues;
382};
383
385
386#endif // QGSCLASSIFICATIONMETHOD_H
QgsClassificationEqualInterval is an implementation of QgsClassificationMethod for equal intervals.
Implementation of a fixed interval classification.
QgsClassificationJenks is an implementation of QgsClassificationMethod for natural breaks based on Je...
QgsClassificationMethod is an abstract class for implementations of classification methods.
double symmetryPoint() const
Returns the symmetry point for symmetric mode.
int codeComplexity() const
Code complexity as the exponent in Big O notation.
bool symmetricModeEnabled() const
Returns if the symmetric mode is enabled.
QFlags< MethodProperty > MethodProperties
virtual QgsClassificationMethod * clone() const =0
Returns a clone of the method.
int labelPrecision() const
Returns the precision for the formatting of the labels.
virtual QString id() const =0
The id of the method as saved in the project, must be unique in registry.
void setLabelTrimTrailingZeroes(bool trimTrailingZeroes)
Defines if the trailing 0 are trimmed in the label.
QVariantMap parameterValues() const
Returns the values of the processing parameters.
ClassPosition
Defines the class position.
@ LowerBound
The class is at the lower 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...
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads extra information to apply it to the method.
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes extra information about the method.
QString labelFormat() const
Returns the format of the label for the classes.
virtual bool valuesRequired() const
Returns if the method requires values to calculate the classes If not, bounds are sufficient.
virtual QString name() const =0
The readable and translate name of the method.
void setLabelFormat(const QString &format)
Defines the format of the labels for the classes, using %1 and %2 for the bounds.
virtual QIcon icon() const
The icon of the method.
bool labelTrimTrailingZeroes() const
Returns if the trailing 0 are trimmed in the label.
QgsProcessingParameterDefinitions parameterDefinitions() const
Returns the list of parameters.
MethodProperty
Flags for the classification method.
bool symmetricModeAvailable() const
Returns if the method supports symmetric calculation.
QgsClassificationMethod::MethodProperties flags() const
Returns the classification flags.
QgsClassificationPrettyBreaks is an implementation of QgsClassificationMethod for pretty breaks.
QgsClassificationQuantile is an implementation of QgsClassificationMethod based on quantiles.
QgsClassificationRange contains the information about a classification range.
QgsClassificationRange(const QString &label, double lowerBound, double upperBound)
Constructor.
QString label() const
Returns the lower bound.
double upperBound() const
Returns the upper bound.
double lowerBound() const
Returns the lower bound.
QgsClassificationCustom is an implementation of QgsClassificationMethod based on standard deviation.
Base class for the definition of processing parameters.
The class is used as a container of context for various read/write operations on other objects.
Represents a vector layer which manages a vector based data sets.
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
#define str(x)
Definition qgis.cpp:38
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_ABSTRACT
Definition qgis_sip.h:213
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_INOUT
Definition qgis_sip.h:71
#define SIP_END
Definition qgis_sip.h:208
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)