Class: QgsClassificationMethod

An abstract class for implementations of classification methods.

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

Inheritance diagram of qgis.core.QgsClassificationMethod

Subclasses

QgsClassificationCustom

A dummy implementation class method which does not compute any breaks.

QgsClassificationEqualInterval

A classification method which uses equal width intervals.

QgsClassificationFixedInterval

Implementation of a fixed interval classification.

QgsClassificationJenks

A classification method for natural breaks, based on Jenks method.

QgsClassificationLogarithmic

Implementation of a logarithmic scale method for classification.

QgsClassificationPrettyBreaks

A classification method which applies pretty breaks to data.

QgsClassificationQuantile

A classification method which creates classes based on quantiles.

QgsClassificationStandardDeviation

A classification method which classifies based on standard deviation of values.

class qgis.core.QgsClassificationMethod[source]

Bases: object

__init__(properties: QgsClassificationMethod.MethodProperties | QgsClassificationMethod.MethodProperty = QgsClassificationMethod.NoFlag, codeComplexity: int = 1)

Creates a classification method.

Parameters:
__init__(a0: QgsClassificationMethod)
Parameters:

a0 (QgsClassificationMethod)

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.

classes(self, values: Iterable[float], nclasses: int) -> List[QgsClassificationRange] This will calculate the classes for a list of values.

Parameters:
  • values – The list of values

  • nclasses – The number of classes to be returned

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 – The minimum value for the breaks

  • maximum – The maximum value for the breaks

  • nclasses – 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:

QgsClassificationMethod.MethodProperties

virtual icon(self) QIcon[source]

The icon of the method

Return type:

QIcon

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

labelForRange(self, range: QgsRendererRange, position: QgsClassificationMethod.ClassPosition = QgsClassificationMethod.Inner) -> str Returns the label for a range

Parameters:
  • lowerValue (float)

  • upperValue (float)

  • position (QgsClassificationMethod.ClassPosition = QgsClassificationMethod.Inner)

Return type:

str

labelFormat(self) str[source]

Returns the format of the label for the classes

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]

abstract name(self) str[source]

The readable and translate name of the method

Return type:

str

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:

List[QgsProcessingParameterDefinition]

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:
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: