Class: QgsClassificationMethod

class qgis.core.QgsClassificationMethod

Bases: sip.wrapper

QgsClassificationMethod is an abstract class for implementations of classification methods

New in version 3.10.

QgsClassificationMethod(properties: Union[QgsClassificationMethod.MethodProperties, QgsClassificationMethod.MethodProperty] = QgsClassificationMethod.NoFlag, codeComplexity: int = 1) Creates a classification method.

Parameters:
  • properties – The properties of the implemented method

  • codeComplexity – as the exponent in the big O notation

QgsClassificationMethod(QgsClassificationMethod)

Methods

classes

This will calculate the classes for a given layer to define the classes.

clone

Returns a clone of the method.

codeComplexity

Code complexity as the exponent in Big O notation

create

Reads the DOM element and return a new classification method from it

flags

Returns the classification flags.

icon

The icon of the method

id

The id of the method as saved in the project, must be unique in registry

labelForRange

Returns the label for a range

labelFormat

Returns the format of the label for the classes

labelPrecision

Returns the precision for the formatting of the labels

labelTrimTrailingZeroes

Returns if the trailing 0 are trimmed in the label

makeBreaksSymmetric

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.

name

The readable and translate name of the method

parameterDefinition

Returns the parameter from its name

parameterDefinitions

Returns the list of parameters

parameterValues

Returns the values of the processing parameters.

rangesToBreaks

Transforms a list of classes to a list of breaks

readXml

Reads extra information to apply it to the method

save

Saves the method to a DOM element and return it

setLabelFormat

Defines the format of the labels for the classes, using %1 and %2 for the bounds

setLabelPrecision

Defines the precision for the formatting of the labels

setLabelTrimTrailingZeroes

Defines if the trailing 0 are trimmed in the label

setParameterValues

Defines the values of the additional parameters

setSymmetricMode

Defines if the symmetric mode is enables and configures its parameters.

symmetricModeAvailable

Returns if the method supports symmetric calculation

symmetricModeEnabled

Returns if the symmetric mode is enabled

symmetryAstride

Returns if the symmetric mode is astride if True, it will remove the symmetry point break so that the 2 classes form only one

symmetryPoint

Returns the symmetry point for symmetric mode

valuesRequired

Returns if the method requires values to calculate the classes If not, bounds are sufficient

writeXml

Writes extra information about the method

Attributes

IgnoresClassCount

Inner

LowerBound

MAX_PRECISION

MIN_PRECISION

NoFlag

SymmetricModeAvailable

UpperBound

ValuesNotRequired

class ClassPosition

Bases: int

IgnoresClassCount = 8
Inner = 1
LowerBound = 0
MAX_PRECISION = 15
MIN_PRECISION = -6
class MethodProperties
class MethodProperties(Union[QgsClassificationMethod.MethodProperties, QgsClassificationMethod.MethodProperty])
class MethodProperties(QgsClassificationMethod.MethodProperties)

Bases: sip.wrapper

class MethodProperty

Bases: int

NoFlag = 0
SymmetricModeAvailable = 4
UpperBound = 2
ValuesNotRequired = 2
classes(self, layer: QgsVectorLayer, expression: str, nclasses: int) List[QgsClassificationRange]

This will calculate the classes for a given layer to define the classes.

Parameters:
  • layer (QgsVectorLayer) – The vector layer

  • expression (str) – The name of the field on which the classes are calculated

  • nclasses (int) – The number of classes to be returned

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]

clone(self) QgsClassificationMethod

Returns a clone of the method. Implementation can take advantage of copyBase method which copies the parameters of the base class

Return type:

QgsClassificationMethod

codeComplexity(self) int

Code complexity as the exponent in Big O notation

Return type:

int

create(element: QDomElement, context: QgsReadWriteContext) QgsClassificationMethod

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:

QgsClassificationMethod

flags(self) QgsClassificationMethod.MethodProperties

Returns the classification flags.

New in version 3.26.

Return type:

QgsClassificationMethod.MethodProperties

icon(self) QIcon

The icon of the method

Return type:

QIcon

id(self) str

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

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

Returns the format of the label for the classes

Return type:

str

labelPrecision(self) int

Returns the precision for the formatting of the labels

Return type:

int

labelTrimTrailingZeroes(self) bool

Returns if the trailing 0 are trimmed in the label

Return type:

bool

makeBreaksSymmetric(breaks: Iterable[float], symmetryPoint: float, astride: bool) List[float]

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]

name(self) str

The readable and translate name of the method

Return type:

str

parameterDefinition(self, parameterName: str) QgsProcessingParameterDefinition

Returns the parameter from its name

New in version 3.12.

Parameters:

parameterName (str) –

Return type:

QgsProcessingParameterDefinition

parameterDefinitions(self) List[QgsProcessingParameterDefinition]

Returns the list of parameters

New in version 3.12.

Return type:

List[QgsProcessingParameterDefinition]

parameterValues(self) Dict[str, Any]

Returns the values of the processing parameters. One could use QgsProcessingParameters.parameterAsXxxx to retrieve the actual value of a parameter.

New in version 3.12.

Return type:

Dict[str, Any]

rangesToBreaks(classes: Iterable[QgsClassificationRange]) List[float]

Transforms a list of classes to a list of breaks

Parameters:

classes (Iterable[QgsClassificationRange]) –

Return type:

List[float]

readXml(self, element: QDomElement, context: QgsReadWriteContext)

Reads extra information to apply it to the method

Parameters:
save(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement

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)

Defines the format of the labels for the classes, using %1 and %2 for the bounds

Parameters:

format (str) –

setLabelPrecision(self, labelPrecision: int)

Defines the precision for the formatting of the labels

Parameters:

labelPrecision (int) –

setLabelTrimTrailingZeroes(self, trimTrailingZeroes: bool)

Defines if the trailing 0 are trimmed in the label

Parameters:

trimTrailingZeroes (bool) –

setParameterValues(self, values: Dict[str, Any])

Defines the values of the additional parameters

New in version 3.12.

Parameters:

values (Dict[str) –

setSymmetricMode(self, enabled: bool, symmetryPoint: float = 0, symmetryAstride: bool = False)

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

Returns if the method supports symmetric calculation

Return type:

bool

symmetricModeEnabled(self) bool

Returns if the symmetric mode is enabled

Return type:

bool

symmetryAstride(self) bool

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

Returns the symmetry point for symmetric mode

Return type:

float

valuesRequired(self) bool

Returns if the method requires values to calculate the classes If not, bounds are sufficient

Return type:

bool

writeXml(self, element: QDomElement, context: QgsReadWriteContext)

Writes extra information about the method

Parameters: