“Geometry expressions offer a powerful way to manipulate attribute value, geometry and variables in order to dynamically change features within a layer”
The geometry functions are a special group of functions that are used to manipulate the geometry of layers. The geometry functions can be used in multiple places like labelling and symbology. When the geometry expressions are used in labelling they act like virtual fields/virtual layers where they evaluate the expressions on the fly and render them independent of the attribute table.
In this module, we will look at how we can use the geometry functions to generate labels.
Goal: To learn how to use the geometry functions to mask labels
dams
and rivers
using the columns name
.Vaaldam
.NB In cartographic standards rivers flow into dams and as such a rivers label should not be visible on top of the dam.
geometric
expression.dams
that uses the expression Area label
. Adjust the label settings so that the label fits within the polygon.NB To prevent overriding the first rule switch to Rule Based
labelling which allows you to define multiple label rules for the layer.
Name | Expectation |
---|---|
Area label |
round( area(transform( $geometry ,'EPSG:4326','EPSG:3857')) / 10000,3) |
geometric |
if (aggregate(layer:='dams', aggregate:='max', expression:="name", filter:=intersects( $geometry, geometry(@parent) ) ), '', "name") |
Geometry functions are very useful as they allow on-the-fly computation of values. This reduces the need to have to create multiple layers or attributes to hold certain values. When using the geometry functions in labelling you have to take into consideration the number of features that are in the layer as this tends to make it slow.
Example: x(line_interpolate_point($geometry,0.7*$length))
The function above places a label at 70 % of the length of the line.
What is a geometry function:
When using the geometry functions to calculate area does the data need to be in a projected co ordinate reference system:
The units of area can only be metres.: