Aggregate functions in QGIS explained with simplicity - Part One
Luis Eduardo Perez Graterol
Analista y desarrollador de SIG comerciales y Open Source
Introduction
This is the first of a series of articles focused on the most powerful but complex expression of QGIS, the aggregate function. The objective is to explain its use and syntax in a gradual, simple and didactic way.
QGIS is a powerful software that allows the processing of information accurately located on the Earth's surface, using a series of functions and expressions through which geoprocesses can be executed, as well as advanced configuration of elements such as labeling, symbology and cartographic output (Atlas).
Expressions
QGIS is configured to work with two programming languages C++ and Python, a situation that facilitates developers and users to create expressions with which they can execute predefined processes, create new elements and manipulate data structures, also allows access to global and context variables, references to objects, among others.?
Expressions are fully integrated in QGIS. With each new version, the number of available expressions increases. Expressions are one of the fastest developing aspects of the software, due to the need to provide greater integration and ease of use.
By means of simple and complex expressions it is possible to perform a great variety of processes, which will facilitate the analysis and cartographic visualization, among them we have:?
How are the expressions organized?
As you can see in the image, the Expression Dialog is made up of three (03) panels, on the left the space where we will write the expression, in the middle the list of expressions and on the right a description of the selected expression.
An important aspect of the structure of the expressions is that they are generally made up of three (03) basic elements:
How do expressions work?
There are two fundamental aspects about the behavior of expressions:
1.- Expressions, whether variables or functions are linked to the active layer:
领英推荐
2.- Expressions that execute functions, for example: the calculation of area ($area or area()), perform a sequential path from the first feature to the last one.
What is a feature?
As shown in the image above, this term encapsulates the geometry and its corresponding attribute.
Aggregates Expressions
The first category of the Expression Dialog is the Aggregates. These functions allow you to group, summarize, totalize values and geometries.?
The simplest use is to generate statistics of a numeric field of a layer, for example: the average population of countries: mean("Population").?
The expressions for calculating statistics are:
The Aggregates functions have clauses, similar to those of the SQL query language, by means of which we can refine the expressions, optimizing the queries or calculations performed.?Among them:
The aggregate function a very special expression
One of the most important functions within the Aggregates is the aggregate function, which allows implementing all the other aggregate expressions in a single expression.
By using it, users can obtain great advantages since it can be used to perform spatial and/or attribute operations involving more than one layer.
Function syntax:
aggregate(layer:= ,??aggregate:= ,??expression:= ,??order_by:= , filter:= )??
You can read the continuation of the article with the development of the aggregate function in the following link: aggregate function