Class: QgsPropertyTransformer

class qgis.core.QgsPropertyTransformer

Bases: sip.wrapper

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.

New in version 3.0.

QgsPropertyTransformer(minValue: float = 0, maxValue: float = 1) Constructor for QgsPropertyTransformer

Parameters:
  • minValue – minimum expected value from source property

  • maxValue – maximum expected value from source property

QgsPropertyTransformer(other: QgsPropertyTransformer) Copy constructor.

Methods

clone

Returns a clone of the transformer.

create

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

curveTransform

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

fromExpression

Attempts to parse an expression into a corresponding property transformer.

loadVariant

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

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.

toExpression

Converts the transformer to a QGIS expression string.

toVariant

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

transform

Calculates the transform of a value.

transformNumeric

Applies base class numeric transformations.

transformerType

Returns the transformer type.

Attributes

ColorRampTransformer

GenericNumericTransformer

SizeScaleTransformer

ColorRampTransformer = 2
GenericNumericTransformer = 0
SizeScaleTransformer = 1
class Type

Bases: int

clone(self) QgsPropertyTransformer

Returns a clone of the transformer.

Return type:

QgsPropertyTransformer

create(type: QgsPropertyTransformer.Type) QgsPropertyTransformer

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

Parameters:

type (QgsPropertyTransformer.Type) – transformer type to create

Return type:

QgsPropertyTransformer

curveTransform(self) QgsCurveTransform

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

Return type:

QgsCurveTransform

fromExpression(expression: str) Tuple[QgsPropertyTransformer, str, str]

Attempts to parse an expression into a corresponding property transformer.

Parameters:

expression (str) – expression to parse

Return type:

Tuple[QgsPropertyTransformer, str, str]

Returns:

  • corresponding property transformer, or None if expression could not

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

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

be parsed to a transformer.

loadVariant(self, transformer: Any) bool

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

Returns the maximum value expected by the transformer.

See also

minValue()

See also

setMaxValue()

Return type:

float

minValue(self) float

Returns the minimum value expected by the transformer.

See also

maxValue()

See also

setMinValue()

Return type:

float

setCurveTransform(self, transform: QgsCurveTransform)

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 (QgsCurveTransform) –

setMaxValue(self, max: float)

Sets the maximum value expected by the transformer.

Parameters:

max (float) – maximum value

See also

setMinValue()

See also

maxValue()

setMinValue(self, min: float)

Sets the minimum value expected by the transformer.

Parameters:

min (float) – minimum value

See also

setMaxValue()

See also

minValue()

toExpression(self, baseExpression: str) str

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

Parameters:

baseExpression (str) –

Return type:

str

toVariant(self) Any

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

transform(self, context: QgsExpressionContext, value: Any) Any

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

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

transformerType(self) QgsPropertyTransformer.Type

Returns the transformer type.

Return type:

QgsPropertyTransformer.Type