Subgroup: Expression

Class: QgsExpressionFunction

class qgis.core.QgsExpressionFunction

Bases: sip.wrapper

A abstract base class for defining QgsExpression functions.

Methods

aliases Returns a list of possible aliases for the function.
allParamsStatic This will return true if all the params for the provided function node are static within the constraints imposed by the context within the given parent.
func Returns result of evaluating the function.
group Returns the first group which the function belongs to.
groups Returns a list of the groups the function belongs to.
handlesNull
helpText The help text for the function.
isContextual Returns whether the function is only available if provided by a QgsExpressionContext object.
isDeprecated Returns true if the function is deprecated and should not be presented as a valid option to users in expression builders.
isStatic Will be called during prepare to determine if the function is static.
lazyEval True if this function should use lazy evaluation.
minParams The minimum number of parameters this function takes.
name The name of the function.
parameters Returns the list of named parameters for the function, if set.
params The number of parameters this function takes.
prepare This will be called during the prepare step() of an expression if it is not static.
referencedColumns Returns a set of field names which are required for this function.
run
usesGeometry Does this function use a geometry object.

Attributes

class Parameter

Bases: sip.wrapper

Represents a single parameter passed to a function.

New in version 2.16.

defaultValue(self) → Any

Returns the default value for the parameter.

name(self) → str

Returns the name of the parameter.

optional(self) → bool

Returns true if the parameter is optional.

aliases(self) → List[str]

Returns a list of possible aliases for the function. These include other permissible names for the function, e.g., deprecated names.

Returns:list of known aliases

New in version 2.9.

allParamsStatic(node: QgsExpressionNodeFunction, parent: QgsExpression, context: QgsExpressionContext) → bool

This will return true if all the params for the provided function node are static within the constraints imposed by the context within the given parent.

This can be used as callback for custom implementations of subclasses. It is the default for implementation for StaticFunction.isStatic.

New in version 3.0.

func(self, values: List[Any], context: QgsExpressionContext, parent: QgsExpression, node: QgsExpressionNodeFunction) → Any

Returns result of evaluating the function.

Parameters:
  • values – list of values passed to the function
  • context – context expression is being evaluated against
  • parent – parent expression
  • node – expression node
Returns:

result of function

group(self) → str

Returns the first group which the function belongs to.

Note

consider using groups() instead, as some functions naturally belong in multiple groups

groups(self) → List[str]

Returns a list of the groups the function belongs to.

New in version 3.0.

See also

group()

handlesNull(self) → bool
helpText(self) → str

The help text for the function.

isContextual(self) → bool

Returns whether the function is only available if provided by a QgsExpressionContext object.

New in version 2.12.

isDeprecated(self) → bool

Returns true if the function is deprecated and should not be presented as a valid option to users in expression builders.

New in version 3.0.

isStatic(self, node: QgsExpressionNodeFunction, parent: QgsExpression, context: QgsExpressionContext) → bool

Will be called during prepare to determine if the function is static. A function is static if it will return the same value for every feature with different attributes and/or geometry.

By default this will return true, if all arguments that have been passed to the function are also static.

New in version 3.0.

lazyEval(self) → bool

True if this function should use lazy evaluation. Lazy evaluation functions take QgsExpression.Node objects rather than the node results when called. You can use node->eval(parent, feature) to evaluate the node and return the result Functions are non lazy default and will be given the node return value when called.

minParams(self) → int

The minimum number of parameters this function takes.

name(self) → str

The name of the function.

parameters(self) → object

Returns the list of named parameters for the function, if set.

New in version 2.16.

params(self) → int

The number of parameters this function takes.

prepare(self, node: QgsExpressionNodeFunction, parent: QgsExpression, context: QgsExpressionContext) → bool

This will be called during the prepare step() of an expression if it is not static.

This can be used by functions to do any preparation steps that might help to speedup the upcoming evaluation.

New in version 3.0.

referencedColumns(self, node: QgsExpressionNodeFunction) → Set[str]

Returns a set of field names which are required for this function. May contain QgsFeatureRequest.AllAttributes to signal that all attributes are required. If in doubt this will return more fields than strictly required.

New in version 3.0.

run(self, args: QgsExpressionNode.NodeList, context: QgsExpressionContext, parent: QgsExpression, node: QgsExpressionNodeFunction) → Any
usesGeometry(self, node: QgsExpressionNodeFunction) → bool

Does this function use a geometry object.