Class: QgsAggregateCalculator¶
- class qgis.core.QgsAggregateCalculator¶
Bases:
sip.wrapper
Utility class for calculating aggregates for a field (or expression) over the features from a vector layer. It is recommended that
QgsVectorLayer.aggregate()
is used rather then directly using this class, as theQgsVectorLayer
method can handle delegating aggregate calculation to a data provider for remote calculation.New in version 2.16.
QgsAggregateCalculator(layer:
QgsVectorLayer
) Constructor for QgsAggregateCalculator.- Parameters:
layer – vector layer to calculate aggregate from
QgsAggregateCalculator(
QgsAggregateCalculator
)Methods
Structured information for available aggregates.
Calculates the value of an aggregate.
Returns the delimiter used for joining values with the StringConcatenate aggregate.
Returns the friendly display name for a
aggregate
.Returns the filter which limits the features used during the aggregate calculation.
Returns the last error encountered during the aggregate calculation.
Returns the associated vector layer.
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
Sets a filter to limit the features used during the aggregate calculation.
Sets a filter to limit the features used during the aggregate calculation.
Sets all aggregate parameters from a parameter bundle.
Converts a string to a aggregate type.
Attributes
- class Aggregate¶
Bases:
int
- class AggregateInfo¶
- class AggregateInfo(QgsAggregateCalculator.AggregateInfo)
Bases:
sip.wrapper
- function¶
- name¶
- supportedTypes¶
- class AggregateParameters¶
- class AggregateParameters(QgsAggregateCalculator.AggregateParameters)
Bases:
sip.wrapper
- delimiter¶
- filter¶
- orderBy¶
- ArrayAggregate = 20¶
- Count = 0¶
- CountDistinct = 1¶
- CountMissing = 2¶
- FirstQuartile = 13¶
- GeometryCollect = 19¶
- InterQuartileRange = 15¶
- Majority = 12¶
- Max = 4¶
- Mean = 6¶
- Median = 7¶
- Min = 3¶
- Minority = 11¶
- Range = 10¶
- StDev = 8¶
- StDevSample = 9¶
- StringConcatenate = 18¶
- StringConcatenateUnique = 21¶
- StringMaximumLength = 17¶
- StringMinimumLength = 16¶
- Sum = 5¶
- ThirdQuartile = 14¶
- aggregates() List[QgsAggregateCalculator.AggregateInfo] ¶
Structured information for available aggregates.
New in version 3.2.
- Return type:
- calculate(self, aggregate: QgsAggregateCalculator.Aggregate, fieldOrExpression: str, context: QgsExpressionContext = None, feedback: QgsFeedback = None) Tuple[Any, bool] ¶
Calculates the value of an aggregate.
- Parameters:
aggregate (QgsAggregateCalculator.Aggregate) – aggregate to calculate
fieldOrExpression (str) – source field or expression to use as basis for aggregated values. If an expression is used, then the context parameter must be set.
context (
QgsExpressionContext
= None) – expression context for evaluating expressionsok – if specified, will be set to
True
if aggregate calculation was successful. Ifok
isFalse
thenlastError()
can be used to retrieve a descriptive error message.feedback (
QgsFeedback
= None) – optional feedback argument for early cancellation (since QGIS 3.22). If set, this will take precedence over any feedback object set on the expressioncontext
.
- Return type:
Tuple[Any, bool]
- Returns:
calculated aggregate value
- delimiter(self) str ¶
Returns the delimiter used for joining values with the StringConcatenate aggregate.
See also
- Return type:
str
- displayName(aggregate: QgsAggregateCalculator.Aggregate) str ¶
Returns the friendly display name for a
aggregate
.New in version 3.22.
- Parameters:
aggregate (QgsAggregateCalculator.Aggregate) –
- Return type:
str
- filter(self) str ¶
Returns the filter which limits the features used during the aggregate calculation.
See also
- Return type:
str
- lastError(self) str ¶
Returns the last error encountered during the aggregate calculation.
New in version 3.22.
- Return type:
str
- layer(self) QgsVectorLayer ¶
Returns the associated vector layer.
- Return type:
- setDelimiter(self, delimiter: str)¶
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
- Parameters:
delimiter (str) – string delimiter
See also
- setFidsFilter(self, fids: object)¶
Sets a filter to limit the features used during the aggregate calculation. If an expression filter is set, it will override this filter.
- Parameters:
fids (object) – feature ids for feature filtering, and empty list will return no features.
See also
- setFilter(self, filterExpression: str)¶
Sets a filter to limit the features used during the aggregate calculation.
- Parameters:
filterExpression (str) – expression for filtering features, or empty string to remove filter
See also
- setParameters(self, parameters: QgsAggregateCalculator.AggregateParameters)¶
Sets all aggregate parameters from a parameter bundle.
- Parameters:
parameters (QgsAggregateCalculator.AggregateParameters) – aggregate parameters
- stringToAggregate(string: str) Tuple[QgsAggregateCalculator.Aggregate, bool] ¶
Converts a string to a aggregate type.
- Parameters:
string (str) – string to convert
ok – if specified, will be set to
True
if conversion was successful
- Return type:
Tuple[QgsAggregateCalculator.Aggregate, bool]
- Returns:
aggregate type