“QGIS can display labels based on any attribute or expression. Labels can be used to emphasise and name places on the map and to explain things verbally which can't be explained with graphical elements”
In this module, we will look at how to use labels. We assume you already know the basics of labelling so we will focus on getting a bit more out of the QGIS labelling engine.
Goal: Create rule based labels for roads
Name | Expectation |
---|---|
Label with |
name |
Major roads |
CASE WHEN "type" = 'Major Highway' OR "type" = 'Beltway' OR "type" = 'Secondary Highway' THEN 1 ELSE 0 END |
Font |
Arial Bold, 13pt, White |
Background SVG |
background_security.svg |
Background size |
12mm (tweak as needed) |
Background colour |
#394f76 |
Background outline colour, border width |
#d8d8d8, 1 symbol unit |
Rotation |
0 |
Placement |
Horizontal |
Other |
ELSE (just enter ELSE directly in the rule expression without using the expression editor) |
In order to do sensible labelling (i.e. labelling that is clear and relevant) you should pay particular attention to these things:
Label text can be defined using an expression. This gives you a lot of freedom to compute label based on multiple attributes, or even features in another layer.
What will this example expression produce if used in the 'label with' option?: x(centroid($geometry)) || ',' || y(centroid($geometry)):
Which of these expressions would change the label to red if the major road is a toll (try each one on the text color property to see):