[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
|
|
|
{
|
|
|
|
"name": "majority",
|
|
|
|
"type": "function",
|
2020-07-02 01:46:48 +01:00
|
|
|
"groups": ["Aggregates"],
|
[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
|
|
|
"description": "Returns the aggregate majority of values (most commonly occurring value) from a field or expression.",
|
2022-01-07 08:33:29 -05:00
|
|
|
"arguments": [{
|
|
|
|
"arg": "expression",
|
|
|
|
"description": "sub expression of field to aggregate"
|
|
|
|
}, {
|
|
|
|
"arg": "group_by",
|
|
|
|
"optional": true,
|
|
|
|
"description": "optional expression to use to group aggregate calculations"
|
|
|
|
}, {
|
|
|
|
"arg": "filter",
|
|
|
|
"optional": true,
|
|
|
|
"description": "optional expression to use to filter features used to calculate aggregate"
|
|
|
|
}],
|
|
|
|
"examples": [{
|
|
|
|
"expression": "majority(\"class\",group_by:=\"state\")",
|
|
|
|
"returns": "most commonly occurring class value, grouped by state field"
|
|
|
|
}],
|
|
|
|
"tags": ["occurring", "field", "majority", "aggregate"]
|
[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
|
|
|
}
|