“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 |
---|---|
In the Value field choose from the dropdown |
name |
Copy and paste the expression into the Filter filed and name it Major roads in the Description field |
CASE WHEN "type" = 'Major Highway' OR "type" = 'Beltway' OR "type" = 'Secondary Highway' THEN 1 ELSE 0 END |
In the Text tab choose |
Font= Arial, Style = Bold, Size =13pt, Color=White |
In the Background tab enable Draw background, in shape choose SVG, click on the ellipsis find |
background_security.svg |
Size field |
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):
Download the sample data for the lesson.