“Expressions facilitates the manipulation of attribute values and geometry of layers. Expressions can also be used to calculate labels on the fly.”
The geometry functions are a special type of functions which 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 label polygons
Name | Expectation |
---|---|
Vector style |
Fill type = transparent, outline style =dash line |
Area label |
round( area(transform( $geometry ,'EPSG:4326','EPSG:3857')) / 10000,3) |
location |
substr( location,1,6 ) || ' ' || substr( location,8,8) |
X |
x(centroid( $geometry)) |
Y |
y(centroid( $geometry)) |
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.