Class: QgsClassificationMethod¶
An abstract class for implementations of classification methods.
See also
Added in version 3.10.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: clone()
, id()
, name()
Class Hierarchy¶
Subclasses¶
A dummy implementation class method which does not compute any breaks. |
|
A classification method which uses equal width intervals. |
|
Implementation of a fixed interval classification. |
|
A classification method for natural breaks, based on Jenks method. |
|
Implementation of a logarithmic scale method for classification. |
|
A classification method which applies pretty breaks to data. |
|
A classification method which creates classes based on quantiles. |
|
A classification method which classifies based on standard deviation of values. |
Abstract Methods
Returns a clone of the method. |
|
The id of the method as saved in the project, must be unique in registry |
|
The readable and translate name of the method |
Methods
This will calculate the classes for a given layer to define the classes. |
|
This will calculate the classes for a given layer to define the classes. |
|
Code complexity as the exponent in Big O notation |
|
Returns the classification flags. |
|
Returns the label for a range |
|
Returns the format of the label for the classes |
|
Returns the precision for the formatting of the labels |
|
Returns if the trailing 0 are trimmed in the label |
|
Returns the parameter from its name |
|
Returns the list of parameters |
|
Returns the values of the processing parameters. |
|
Saves the method to a DOM element and return it |
|
Defines the format of the labels for the classes, using %1 and %2 for the bounds |
|
Defines the precision for the formatting of the labels |
|
Defines if the trailing 0 are trimmed in the label |
|
Defines the values of the additional parameters |
|
Defines if the symmetric mode is enables and configures its parameters. |
|
Returns if the method supports symmetric calculation |
|
Returns if the symmetric mode is enabled |
|
Returns if the symmetric mode is astride if |
|
Returns the symmetry point for symmetric mode |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsClassificationMethod. See the FAQ for more details.
The icon of the method |
|
Reads extra information to apply it to the method |
|
Returns if the method requires values to calculate the classes If not, bounds are sufficient |
|
Writes extra information about the method |
Static Methods
Reads the DOM element and return a new classification method from it |
|
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically balanced around symmetryPoint Does not put a break on the symmetryPoint. |
|
Transforms a list of classes to a list of breaks |
Attributes
- class qgis.core.QgsClassificationMethod[source]¶
Bases:
object
- __init__(properties: QgsClassificationMethod.MethodProperties | QgsClassificationMethod.MethodProperty = QgsClassificationMethod.NoFlag, codeComplexity: int = 1)
Creates a classification method.
- Parameters:
properties (Union[QgsClassificationMethod.MethodProperties, QgsClassificationMethod.MethodProperty] = QgsClassificationMethod.NoFlag) – The properties of the implemented method
codeComplexity (int = 1) – as the exponent in the big O notation
- __init__(a0: QgsClassificationMethod)
- Parameters:
- class ClassPosition¶
Bases:
int
- IgnoresClassCount = 8¶
- Inner = 1¶
- LowerBound = 0¶
- MAX_PRECISION = 15¶
- MIN_PRECISION = -6¶
- class MethodProperties¶
- class MethodProperties(f: QgsClassificationMethod.MethodProperties | QgsClassificationMethod.MethodProperty)
- class MethodProperties(a0: QgsClassificationMethod.MethodProperties)
Bases:
object
- class MethodProperty¶
Bases:
int
- NoFlag = 0¶
- SymmetricModeAvailable = 4¶
- UpperBound = 2¶
- ValuesNotRequired = 2¶
- classes(self, layer: QgsVectorLayer | None, expression: str | None, nclasses: int) List[QgsClassificationRange] ¶
This will calculate the classes for a given layer to define the classes.
- Parameters:
layer (Optional[QgsVectorLayer]) – The vector layer
expression (Optional[str]) – The name of the field on which the classes are calculated
nclasses (int) – The number of classes to be returned
Deprecated since version 3.38: Use
classesV2()
instead.- Return type:
List[QgsClassificationRange]
- classes(self, values: Iterable[float], nclasses: int) List[QgsClassificationRange]
This will calculate the classes for a list of values.
- Parameters:
values (Iterable[float]) – The list of values
nclasses (int) – The number of classes to be returned
- Return type:
List[QgsClassificationRange]
- classes(self, minimum: float, maximum: float, nclasses: int) List[QgsClassificationRange]
This will calculate the classes for defined bounds without any values.
Warning
If the method implementation requires values, this will return an empty list.
- Parameters:
minimum (float) – The minimum value for the breaks
maximum (float) – The maximum value for the breaks
nclasses (int) – The number of classes to be returned
- Return type:
List[QgsClassificationRange]
- classesV2(self, layer: QgsVectorLayer | None, expression: str | None, nclasses: int)¶
This will calculate the classes for a given layer to define the classes.
- Parameters:
layer (Optional[QgsVectorLayer]) – The vector layer
expression (Optional[str]) – The name of the field on which the classes are calculated
nclasses (int) -> (List[QgsClassificationRange]) – The number of classes to be returned
- Returns:
list of generated classes
error: error string if an error occurred while generating the classes
Added in version 3.38.
- abstract clone(self) QgsClassificationMethod | None ¶
Returns a clone of the method. Implementation can take advantage of copyBase method which copies the parameters of the base class
- Return type:
Optional[QgsClassificationMethod]
- codeComplexity(self) int [source]¶
Code complexity as the exponent in Big O notation
- Return type:
int
- static create(element: QDomElement, context: QgsReadWriteContext) QgsClassificationMethod | None ¶
Reads the DOM element and return a new classification method from it
- Parameters:
element (QDomElement) – the DOM element
context (QgsReadWriteContext) – the read/write context
- Return type:
Optional[QgsClassificationMethod]
- flags(self) QgsClassificationMethod.MethodProperties [source]¶
Returns the classification flags.
Added in version 3.26.
- Return type:
- abstract id(self) str [source]¶
The id of the method as saved in the project, must be unique in registry
- Return type:
str
- labelForRange(self, lowerValue: float, upperValue: float, position: QgsClassificationMethod.ClassPosition = QgsClassificationMethod.Inner) str [source]¶
Returns the label for a range
- Parameters:
lowerValue (float)
upperValue (float)
position (QgsClassificationMethod.ClassPosition = QgsClassificationMethod.Inner)
- Return type:
str
- labelForRange(self, range: QgsRendererRange, position: QgsClassificationMethod.ClassPosition = QgsClassificationMethod.Inner) str [source]
Returns the label for a range
- Parameters:
range (
QgsRendererRange
)position (QgsClassificationMethod.ClassPosition = QgsClassificationMethod.Inner)
- Return type:
str
- labelPrecision(self) int [source]¶
Returns the precision for the formatting of the labels
- Return type:
int
- labelTrimTrailingZeroes(self) bool [source]¶
Returns if the trailing 0 are trimmed in the label
- Return type:
bool
- static makeBreaksSymmetric(breaks: Iterable[float], symmetryPoint: float, astride: bool) List[float] [source]¶
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically balanced around symmetryPoint Does not put a break on the symmetryPoint. This is done before.
- Parameters:
breaks (Iterable[float]) – The breaks of an already-done classification
symmetryPoint (float) – The point around which we want a symmetry
astride (bool) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
- Return type:
List[float]
- parameterDefinition(self, parameterName: str | None) QgsProcessingParameterDefinition | None [source]¶
Returns the parameter from its name
Added in version 3.12.
- Parameters:
parameterName (Optional[str])
- Return type:
Optional[QgsProcessingParameterDefinition]
- parameterDefinitions(self) List[QgsProcessingParameterDefinition] [source]¶
Returns the list of parameters
Added in version 3.12.
- Return type:
- parameterValues(self) Dict[str, Any] [source]¶
Returns the values of the processing parameters. One could use
QgsProcessingParameters
.parameterAsXxxx to retrieve the actual value of a parameter.Added in version 3.12.
- Return type:
Dict[str, Any]
- static rangesToBreaks(classes: Iterable[QgsClassificationRange]) List[float] ¶
Transforms a list of classes to a list of breaks
- Parameters:
classes (Iterable[QgsClassificationRange])
- Return type:
List[float]
- virtual readXml(self, element: QDomElement, context: QgsReadWriteContext)[source]¶
Reads extra information to apply it to the method
- Parameters:
element (QDomElement)
context (QgsReadWriteContext)
- save(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement [source]¶
Saves the method to a DOM element and return it
- Parameters:
doc (QDomDocument) – the DOM document
context (QgsReadWriteContext) – the read/write context
- Return type:
QDomElement
- setLabelFormat(self, format: str | None)[source]¶
Defines the format of the labels for the classes, using %1 and %2 for the bounds
- Parameters:
format (Optional[str])
- setLabelPrecision(self, labelPrecision: int)[source]¶
Defines the precision for the formatting of the labels
- Parameters:
labelPrecision (int)
- setLabelTrimTrailingZeroes(self, trimTrailingZeroes: bool)[source]¶
Defines if the trailing 0 are trimmed in the label
- Parameters:
trimTrailingZeroes (bool)
- setParameterValues(self, values: Dict[str, Any])[source]¶
Defines the values of the additional parameters
Added in version 3.12.
- Parameters:
values (Dict[str, Any])
- setSymmetricMode(self, enabled: bool, symmetryPoint: float = 0, symmetryAstride: bool = False)[source]¶
Defines if the symmetric mode is enables and configures its parameters. If the symmetric mode is not available in the current implementation, calling this method has no effect.
- Parameters:
enabled (bool) – if the symmetric mode is enabled
symmetryPoint (float = 0) – the value of the symmetry point
symmetryAstride (bool = False) – if
True
, it will remove the symmetry point break so that the 2 classes form only one
- symmetricModeAvailable(self) bool [source]¶
Returns if the method supports symmetric calculation
- Return type:
bool
- symmetricModeEnabled(self) bool [source]¶
Returns if the symmetric mode is enabled
- Return type:
bool
- symmetryAstride(self) bool [source]¶
Returns if the symmetric mode is astride if
True
, it will remove the symmetry point break so that the 2 classes form only one- Return type:
bool
- symmetryPoint(self) float [source]¶
Returns the symmetry point for symmetric mode
- Return type:
float
- virtual valuesRequired(self) bool [source]¶
Returns if the method requires values to calculate the classes If not, bounds are sufficient
- Return type:
bool
- virtual writeXml(self, element: QDomElement, context: QgsReadWriteContext)[source]¶
Writes extra information about the method
- Parameters:
element (QDomElement)
context (QgsReadWriteContext)