Class: QgsPropertyTransformer

Abstract base class for objects which transform the calculated value of a property.

Possible uses include transformers which map a value into a scaled size or color from a gradient.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), toExpression(), transform(), transformerType()

Class Hierarchy

Inheritance diagram of qgis.core.QgsPropertyTransformer

Subclasses

QgsColorRampTransformer

QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.

QgsGenericNumericTransformer

QgsPropertyTransformer subclass for scaling an input numeric value into an output numeric value.

QgsSizeScaleTransformer

QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.

Abstract Methods

clone

Returns a clone of the transformer.

toExpression

Converts the transformer to a QGIS expression string.

transform

Calculates the transform of a value.

transformerType

Returns the transformer type.

Methods

curveTransform

Returns the curve transform applied to input values before they are transformed by the individual transform subclasses.

maxValue

Returns the maximum value expected by the transformer.

minValue

Returns the minimum value expected by the transformer.

setCurveTransform

Sets a curve transform to apply to input values before they are transformed by the individual transform subclasses.

setMaxValue

Sets the maximum value expected by the transformer.

setMinValue

Sets the minimum value expected by the transformer.

transformNumeric

Applies base class numeric transformations.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsPropertyTransformer. See the FAQ for more details.

loadVariant

Loads this transformer from a QVariantMap, wrapped in a QVariant.

toVariant

Saves this transformer to a QVariantMap, wrapped in a QVariant.

Static Methods

create

Factory method for creating a new property transformer of the specified type.

fromExpression

Attempts to parse an expression into a corresponding property transformer.

Attributes

ColorRampTransformer

GenericNumericTransformer

SizeScaleTransformer

class qgis.core.QgsPropertyTransformer[source]

Bases: object

__init__(minValue: float = 0, maxValue: float = 1)

Constructor for QgsPropertyTransformer

Parameters:
  • minValue (float = 0) – minimum expected value from source property

  • maxValue (float = 1) – maximum expected value from source property

__init__(other: QgsPropertyTransformer)
Parameters:

other (QgsPropertyTransformer)

ColorRampTransformer = 2
GenericNumericTransformer = 0
SizeScaleTransformer = 1
class Type

Bases: int

abstract clone(self) QgsPropertyTransformer | None[source]

Returns a clone of the transformer.

Return type:

Optional[QgsPropertyTransformer]

static create(type: QgsPropertyTransformer.Type) QgsPropertyTransformer | None[source]

Factory method for creating a new property transformer of the specified type.

Parameters:

type (QgsPropertyTransformer.Type) – transformer type to create

Return type:

Optional[QgsPropertyTransformer]

curveTransform(self) QgsCurveTransform | None[source]

Returns the curve transform applied to input values before they are transformed by the individual transform subclasses.

Return type:

Optional[QgsCurveTransform]

static fromExpression(expression: str | None)[source]

Attempts to parse an expression into a corresponding property transformer.

Parameters:

expression (Optional[str]) -> (Optional[QgsPropertyTransformer]) – expression to parse

Returns:

  • corresponding property transformer, or None if expression could not be parsed to a transformer.

  • baseExpression: the component of the source expression which is used to calculate the input to the property transformer. This an empty string if a field reference is the transformer input.

  • fieldName: a field name which is used to calculate the input to the property transformer. This an empty string if an expression is the transformer input.

virtual loadVariant(self, transformer: Any) bool[source]

Loads this transformer from a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.readVariant to read it from an XML document.

See also

toVariant()

Parameters:

transformer (Any)

Return type:

bool

maxValue(self) float[source]

Returns the maximum value expected by the transformer.

See also

minValue()

See also

setMaxValue()

Return type:

float

minValue(self) float[source]

Returns the minimum value expected by the transformer.

See also

maxValue()

See also

setMinValue()

Return type:

float

setCurveTransform(self, transform: QgsCurveTransform | None)[source]

Sets a curve transform to apply to input values before they are transformed by the individual transform subclasses. Ownership of transform is transferred to the property transformer.

See also

curveTransform()

Parameters:

transform (Optional[QgsCurveTransform])

setMaxValue(self, max: float)[source]

Sets the maximum value expected by the transformer.

Parameters:

max (float) – maximum value

See also

setMinValue()

See also

maxValue()

setMinValue(self, min: float)[source]

Sets the minimum value expected by the transformer.

Parameters:

min (float) – minimum value

See also

setMaxValue()

See also

minValue()

abstract toExpression(self, baseExpression: str | None) str[source]

Converts the transformer to a QGIS expression string. The baseExpression string consists of a sub-expression reflecting the parent property’s state.

Parameters:

baseExpression (Optional[str])

Return type:

str

virtual toVariant(self) Any[source]

Saves this transformer to a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.writeVariant to save it to an XML document.

See also

loadVariant()

Return type:

Any

abstract transform(self, context: QgsExpressionContext, value: Any) Any[source]

Calculates the transform of a value. Derived classes must implement this to perform their transformations on input values

Parameters:
Return type:

Any

transformNumeric(self, input: float) float[source]

Applies base class numeric transformations. Derived classes should call this to transform an input numeric value before they apply any transform to the result. This applies any curve transforms which may exist on the transformer.

Parameters:

input (float)

Return type:

float

abstract transformerType(self) QgsPropertyTransformer.Type[source]

Returns the transformer type.

Return type:

QgsPropertyTransformer.Type