2017-04-04 08:44:22 +02:00
|
|
|
/************************************************************************
|
|
|
|
* This file has been generated automatically from *
|
|
|
|
* *
|
|
|
|
* src/core/qgsaggregatecalculator.h *
|
|
|
|
* *
|
|
|
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-16 12:01:14 +10:00
|
|
|
class QgsAggregateCalculator
|
|
|
|
{
|
2017-04-04 08:44:22 +02:00
|
|
|
%Docstring
|
|
|
|
Utility class for calculating aggregates for a field (or expression) over the features
|
2017-12-15 10:36:55 -04:00
|
|
|
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.
|
|
|
|
|
2017-04-04 08:44:22 +02:00
|
|
|
.. versionadded:: 2.16
|
|
|
|
%End
|
2016-05-16 12:01:14 +10:00
|
|
|
|
|
|
|
%TypeHeaderCode
|
2017-04-04 08:44:22 +02:00
|
|
|
#include "qgsaggregatecalculator.h"
|
2016-05-16 12:01:14 +10:00
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
2017-11-01 21:14:34 +01:00
|
|
|
struct AggregateInfo
|
|
|
|
{
|
2017-11-02 10:20:49 +01:00
|
|
|
QString function; //!< The expression function
|
|
|
|
QString name; //!< A translated, human readable name
|
|
|
|
QSet<QVariant::Type> supportedTypes; //!< This aggregate function can only be used with these datatypes
|
2017-11-01 21:14:34 +01:00
|
|
|
};
|
|
|
|
|
2016-05-16 12:01:14 +10:00
|
|
|
enum Aggregate
|
|
|
|
{
|
2017-04-04 08:44:22 +02:00
|
|
|
Count,
|
|
|
|
CountDistinct,
|
|
|
|
CountMissing,
|
|
|
|
Min,
|
|
|
|
Max,
|
|
|
|
Sum,
|
|
|
|
Mean,
|
|
|
|
Median,
|
|
|
|
StDev,
|
|
|
|
StDevSample,
|
|
|
|
Range,
|
|
|
|
Minority,
|
|
|
|
Majority,
|
|
|
|
FirstQuartile,
|
|
|
|
ThirdQuartile,
|
|
|
|
InterQuartileRange,
|
|
|
|
StringMinimumLength,
|
|
|
|
StringMaximumLength,
|
|
|
|
StringConcatenate,
|
2017-08-06 15:08:27 +02:00
|
|
|
GeometryCollect,
|
|
|
|
ArrayAggregate
|
[FEATURE] Aggregates for expressions
This commit adds a number of different forms of aggregates to
the expression engine.
1. Aggregates within the current layer, eg sum("passengers")
Supports sub expressions (ie sum("passengers"/2) ), group by
( sum("passengers", group_by:="line_segment") ), and optional
filters ( sum("passengers", filter:= "station_class" > 3 ) )
2. Relational aggregates, which calculate an aggregate over
all matching child features from a relation, eg
relation_aggregate( 'my_relation', 'mean', "some_child_field" )
3. A summary aggregate function, for calculating aggregates
on other layers. Eg aggregate('rail_station_layer','sum',"passengers")
The summary aggregate function supports an optional filter,
making it possible to calculate things like:
aggregate('rail_stations','sum',"passengers",
intersects(@atlas_geometry, $geometry ) )
for calculating the total number of passengers for the stations
inside the current atlas feature
In all cases the calculations are cached inside the expression
context, so they only need to be calculated once for each
set of expression evaluations.
Sponsored by Kanton of Zug, Switzerland
2016-05-16 17:30:07 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AggregateParameters
|
|
|
|
{
|
2017-04-04 08:44:22 +02:00
|
|
|
|
[FEATURE] Aggregates for expressions
This commit adds a number of different forms of aggregates to
the expression engine.
1. Aggregates within the current layer, eg sum("passengers")
Supports sub expressions (ie sum("passengers"/2) ), group by
( sum("passengers", group_by:="line_segment") ), and optional
filters ( sum("passengers", filter:= "station_class" > 3 ) )
2. Relational aggregates, which calculate an aggregate over
all matching child features from a relation, eg
relation_aggregate( 'my_relation', 'mean', "some_child_field" )
3. A summary aggregate function, for calculating aggregates
on other layers. Eg aggregate('rail_station_layer','sum',"passengers")
The summary aggregate function supports an optional filter,
making it possible to calculate things like:
aggregate('rail_stations','sum',"passengers",
intersects(@atlas_geometry, $geometry ) )
for calculating the total number of passengers for the stations
inside the current atlas feature
In all cases the calculations are cached inside the expression
context, so they only need to be calculated once for each
set of expression evaluations.
Sponsored by Kanton of Zug, Switzerland
2016-05-16 17:30:07 +10:00
|
|
|
QString filter;
|
|
|
|
|
|
|
|
QString delimiter;
|
2016-05-16 12:01:14 +10:00
|
|
|
};
|
|
|
|
|
2017-04-04 08:44:22 +02:00
|
|
|
QgsAggregateCalculator( const QgsVectorLayer *layer );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Constructor for QgsAggregateCalculator.
|
2017-12-15 21:36:08 -04:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param layer: vector layer to calculate aggregate from
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
|
|
|
|
|
|
|
const QgsVectorLayer *layer() const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns the associated vector layer.
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
|
|
|
|
|
|
|
void setParameters( const AggregateParameters ¶meters );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Sets all aggregate parameters from a parameter bundle.
|
2017-12-15 21:36:08 -04:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param parameters: aggregate parameters
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
|
|
|
|
|
|
|
void setFilter( const QString &filterExpression );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Sets a filter to limit the features used during the aggregate calculation.
|
2017-12-15 21:36:08 -04:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param filterExpression: expression for filtering features, or empty string to remove filter
|
|
|
|
|
2018-01-09 17:26:37 -04:00
|
|
|
.. seealso:: :py:func:`filter`
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
|
|
|
|
2016-05-16 12:01:14 +10:00
|
|
|
QString filter() const;
|
2017-04-04 08:44:22 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns the filter which limits the features used during the aggregate calculation.
|
|
|
|
|
2018-01-09 17:26:37 -04:00
|
|
|
.. seealso:: :py:func:`setFilter`
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
2016-05-16 12:01:14 +10:00
|
|
|
|
2017-04-04 08:44:22 +02:00
|
|
|
void setDelimiter( const QString &delimiter );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
|
2017-12-15 21:36:08 -04:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param delimiter: string delimiter
|
|
|
|
|
2018-01-09 17:26:37 -04:00
|
|
|
.. seealso:: :py:func:`delimiter`
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
[FEATURE] Aggregates for expressions
This commit adds a number of different forms of aggregates to
the expression engine.
1. Aggregates within the current layer, eg sum("passengers")
Supports sub expressions (ie sum("passengers"/2) ), group by
( sum("passengers", group_by:="line_segment") ), and optional
filters ( sum("passengers", filter:= "station_class" > 3 ) )
2. Relational aggregates, which calculate an aggregate over
all matching child features from a relation, eg
relation_aggregate( 'my_relation', 'mean', "some_child_field" )
3. A summary aggregate function, for calculating aggregates
on other layers. Eg aggregate('rail_station_layer','sum',"passengers")
The summary aggregate function supports an optional filter,
making it possible to calculate things like:
aggregate('rail_stations','sum',"passengers",
intersects(@atlas_geometry, $geometry ) )
for calculating the total number of passengers for the stations
inside the current atlas feature
In all cases the calculations are cached inside the expression
context, so they only need to be calculated once for each
set of expression evaluations.
Sponsored by Kanton of Zug, Switzerland
2016-05-16 17:30:07 +10:00
|
|
|
|
|
|
|
QString delimiter() const;
|
2017-04-04 08:44:22 +02:00
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Returns the delimiter used for joining values with the StringConcatenate aggregate.
|
|
|
|
|
2018-01-09 17:26:37 -04:00
|
|
|
.. seealso:: :py:func:`setDelimiter`
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
|
|
|
|
|
|
|
QVariant calculate( Aggregate aggregate, const QString &fieldOrExpression,
|
|
|
|
QgsExpressionContext *context = 0, bool *ok = 0 ) const;
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Calculates the value of an aggregate.
|
2017-12-15 21:36:08 -04:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param aggregate: aggregate to calculate
|
|
|
|
:param fieldOrExpression: source field or expression to use as basis for aggregated values.
|
|
|
|
If an expression is used, then the context parameter must be set.
|
|
|
|
:param context: expression context for evaluating expressions
|
|
|
|
:param ok: if specified, will be set to true if aggregate calculation was successful
|
|
|
|
|
|
|
|
:return: calculated aggregate value
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
[FEATURE] Aggregates for expressions
This commit adds a number of different forms of aggregates to
the expression engine.
1. Aggregates within the current layer, eg sum("passengers")
Supports sub expressions (ie sum("passengers"/2) ), group by
( sum("passengers", group_by:="line_segment") ), and optional
filters ( sum("passengers", filter:= "station_class" > 3 ) )
2. Relational aggregates, which calculate an aggregate over
all matching child features from a relation, eg
relation_aggregate( 'my_relation', 'mean', "some_child_field" )
3. A summary aggregate function, for calculating aggregates
on other layers. Eg aggregate('rail_station_layer','sum',"passengers")
The summary aggregate function supports an optional filter,
making it possible to calculate things like:
aggregate('rail_stations','sum',"passengers",
intersects(@atlas_geometry, $geometry ) )
for calculating the total number of passengers for the stations
inside the current atlas feature
In all cases the calculations are cached inside the expression
context, so they only need to be calculated once for each
set of expression evaluations.
Sponsored by Kanton of Zug, Switzerland
2016-05-16 17:30:07 +10:00
|
|
|
|
2017-04-04 08:44:22 +02:00
|
|
|
static Aggregate stringToAggregate( const QString &string, bool *ok = 0 );
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Converts a string to a aggregate type.
|
2017-12-15 21:36:08 -04:00
|
|
|
|
2017-12-15 10:36:55 -04:00
|
|
|
:param string: string to convert
|
|
|
|
:param ok: if specified, will be set to true if conversion was successful
|
|
|
|
|
|
|
|
:return: aggregate type
|
2017-04-04 08:44:22 +02:00
|
|
|
%End
|
2016-05-16 12:01:14 +10:00
|
|
|
|
2017-11-01 21:14:34 +01:00
|
|
|
static QList< QgsAggregateCalculator::AggregateInfo > aggregates();
|
|
|
|
%Docstring
|
2017-12-15 10:36:55 -04:00
|
|
|
Structured information for available aggregates.
|
|
|
|
|
2017-11-02 18:06:14 +01:00
|
|
|
.. versionadded:: 3.2
|
2017-11-01 21:14:34 +01:00
|
|
|
%End
|
|
|
|
|
2016-05-16 12:01:14 +10:00
|
|
|
};
|
2017-04-04 08:44:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* This file has been generated automatically from *
|
|
|
|
* *
|
|
|
|
* src/core/qgsaggregatecalculator.h *
|
|
|
|
* *
|
|
|
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
|
|
|
************************************************************************/
|