Utility class for calculating aggregates for a field (or expression) over the features from a vector layer.
More...
#include <qgsaggregatecalculator.h>
|
enum | Aggregate {
Count
, CountDistinct
, CountMissing
, Min
,
Max
, Sum
, Mean
, Median
,
StDev
, StDevSample
, Range
, Minority
,
Majority
, FirstQuartile
, ThirdQuartile
, InterQuartileRange
,
StringMinimumLength
, StringMaximumLength
, StringConcatenate
, GeometryCollect
,
ArrayAggregate
, StringConcatenateUnique
} |
| Available aggregates to calculate. More...
|
|
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 the QgsVectorLayer method can handle delegating aggregate calculation to a data provider for remote calculation.
- Since
- QGIS 2.16
Definition at line 44 of file qgsaggregatecalculator.h.
◆ Aggregate
Available aggregates to calculate.
Not all aggregates are available for all field types.
Enumerator |
---|
Count | Count.
|
CountDistinct | Number of distinct values.
|
CountMissing | Number of missing (null) values.
|
Min | Min of values.
|
Max | Max of values.
|
Sum | Sum of values.
|
Mean | Mean of values (numeric fields only)
|
Median | Median of values (numeric fields only)
|
StDev | Standard deviation of values (numeric fields only)
|
StDevSample | Sample standard deviation of values (numeric fields only)
|
Range | Range of values (max - min) (numeric and datetime fields only)
|
Minority | Minority of values.
|
Majority | Majority of values.
|
FirstQuartile | First quartile (numeric fields only)
|
ThirdQuartile | Third quartile (numeric fields only)
|
InterQuartileRange | Inter quartile range (IQR) (numeric fields only)
|
StringMinimumLength | Minimum length of string (string fields only)
|
StringMaximumLength | Maximum length of string (string fields only)
|
StringConcatenate | Concatenate values with a joining string (string fields only). Specify the delimiter using setDelimiter().
|
GeometryCollect | Create a multipart geometry from aggregated geometries.
|
ArrayAggregate | Create an array of values.
|
StringConcatenateUnique | Concatenate unique values with a joining string (string fields only). Specify the delimiter using setDelimiter().
|
Definition at line 67 of file qgsaggregatecalculator.h.
◆ QgsAggregateCalculator()
QgsAggregateCalculator::QgsAggregateCalculator |
( |
const QgsVectorLayer * |
layer | ) |
|
◆ aggregates()
◆ calculate()
Calculates the value of an aggregate.
- Parameters
-
aggregate | aggregate to calculate |
fieldOrExpression | source field or expression to use as basis for aggregated values. If an expression is used, then the context parameter must be set. |
context | expression context for evaluating expressions |
ok | if specified, will be set to true if aggregate calculation was successful. If ok is false then lastError() can be used to retrieve a descriptive error message. |
feedback | optional feedback argument for early cancellation (since QGIS 3.22). If set, this will take precedence over any feedback object set on the expression context. |
- Returns
- calculated aggregate value
Definition at line 52 of file qgsaggregatecalculator.cpp.
◆ delimiter()
QString QgsAggregateCalculator::delimiter |
( |
| ) |
const |
|
inline |
◆ displayName()
QString QgsAggregateCalculator::displayName |
( |
Aggregate |
aggregate | ) |
|
|
static |
◆ filter()
QString QgsAggregateCalculator::filter |
( |
| ) |
const |
|
inline |
◆ lastError()
QString QgsAggregateCalculator::lastError |
( |
| ) |
const |
|
inline |
Returns the last error encountered during the aggregate calculation.
- Since
- QGIS 3.22
Definition at line 130 of file qgsaggregatecalculator.h.
◆ layer()
◆ setDelimiter()
void QgsAggregateCalculator::setDelimiter |
( |
const QString & |
delimiter | ) |
|
|
inline |
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
- Parameters
-
delimiter | string delimiter |
- See also
- delimiter()
Definition at line 169 of file qgsaggregatecalculator.h.
◆ setFidsFilter()
void QgsAggregateCalculator::setFidsFilter |
( |
const QgsFeatureIds & |
fids | ) |
|
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 | feature ids for feature filtering, and empty list will return no features. |
- See also
- filter()
Definition at line 46 of file qgsaggregatecalculator.cpp.
◆ setFilter()
void QgsAggregateCalculator::setFilter |
( |
const QString & |
filterExpression | ) |
|
|
inline |
Sets a filter to limit the features used during the aggregate calculation.
- Parameters
-
filterExpression | expression for filtering features, or empty string to remove filter |
- See also
- filter()
Definition at line 148 of file qgsaggregatecalculator.h.
◆ setParameters()
Sets all aggregate parameters from a parameter bundle.
- Parameters
-
parameters | aggregate parameters |
Definition at line 39 of file qgsaggregatecalculator.cpp.
◆ stringToAggregate()
Converts a string to a aggregate type.
- Parameters
-
string | string to convert |
ok | if specified, will be set to true if conversion was successful |
- Returns
- aggregate type
Definition at line 188 of file qgsaggregatecalculator.cpp.
The documentation for this class was generated from the following files: