Labels for vector data#
Labels are text that display information or values of the data. In QGIS, you can either select Single Labels or
Rule-based Labelling. For each option, an attribute (value
) that will be displayed on the map. For example, the
name of a city or region. Additionally, you can change the font, font size, colour and some other styling options
for the label text. When you create a map, you can add labels to help your reader understand the map quickly. However,
be aware that too much text information can overload the map with too much information for the reader to process.
Single Labels and Rule-based Labeling#
QGIS offers two methods to display labels: Single Labels and Rule-based Labeling
Single Labels#
Creates a single label style for every feature in the layer. You can select a attribute (value) which will be displayed. For example, the name of a settlement. You need to know which attribute displays the information you want to display. Look at the attribute table of the dataset to find it out.
Adding Single Labels to a Layer#
In the styling panel, click on the
Labels
-tab underneath the Symbology tab.Select
Single labels
.Value
is where you choose the attribute that will be displayed as a label. For example*ADM1_EN*
will display the English names of Nigerian states for each feature in the data set.Let’s change the font: Open the font dropdown menu and select Arial. Make the text
Bold
in the Style dropdown menu. Change the colour by clicking onColour
, and change theSize
to 8 ptLet’s add a white buffer around the label. In the
Labels
tab, you will find a list with different options to style the labels. Right now, we are in theText
menu. SelectBuffer
and check theDraw text buffer
option. This will make the labels stand out more on dark or crowded maps.Click
Apply
andOK
.
Attention
Single Labels are not always useful. For example, if the dataset is too big, or you only want to display certain features in the dataset. In the example below, there are too many settlements to display labels for each settlements. Instead, it might be useful to only display the regional and national capitals. For such a use case, Rule-based Labeling is ideal.
Rule-based Labelling#
Create rules using expressions to select accurately which features are to be labeled. Each rule can have a different text formatting. Use this if you want to have more control over the information that will be displayed as labels. For example, you can filter your data to only display the names of regional capitals.
The rules, or filters, are based on an expression. You can use the Expression string builder
to the right of the Filter option in the label panel.
Adding Rule-based Labels to a Layer#
In the styling panel, click on the
Labels
tab underneath the Symbology tab.Select
Rule-based Labeling
.Add a Rule by clicking on the
+
-button in the left corner of the styling panel. A new window will open in the styling panel. In this window, you will enter the rule (Filter
) and customize the label font, size, and placement. Additionally, you can enter a description.Enter a Filter (red box in the figure below). The easiest way is to use the
Expression string builder
to the right of the Filter option. Click on the -Symbol. A new panel will open.In the Expression String builder enter a rule. In the example in the video below, we want to only display settlements that are either national or regional capitals. This corresponds to the String
("CLASS" = 1 ) OR ("CLASS" = 2)
. We know this because we know our data and have looked at the attribute table beforehand.Click
OK
Set the font and font size.
Click
Apply
.
Note
To add rules to your labels, you need to be familiar with your data! Look at the metadata (in the properties or at the source) and take a look at the attribute table. Think about what the different columns mean and identify the attributes. This might not always be easy, as they might have abbreviated names, but as you work more with data, this will become easier.
Below are some further considerations to keep in mind when using labels:
Only display information that serves the purpose of the map or is helpful to the reader. Useful information can be the name of a settlement or a place, so the reader can assign a certain symbol on the map to this particular place.
If you want to display different types of information as labels, the font needs to be different so the reader can differentiate between the different types of information that is displayed. A good practice is to display the labels in a similar colour to the objects it is referring to. For example, dark blue text for the labels of light blue bodies of water, or brown text for the labels of light-brown houses.
Attention
In most cases, displaying numerical values as labels is confusing to the reader and makes the map to complex. In most cases, for numerical data, you can choose a different visualization such as colours or symbol size.
QGIS places the labels automatically. Sometimes, if you are using a lot of black outlines or dark colours, black text is hard to read on the map. In that case, you can add white buffer around the text to make it visible.
Note
QGIS renders labels automatically.
Sometimes labels can obstruct other symbols. In that case, you can either adjust the placement of the labels in the Label tab, or use the Move a Label, Diagram, or Callout
-tool in Label toolbar
By default, QGIS renders the labels so that they don’t overlap with other labels. This means that not all the labels will be visible if the data is dense or rendered close to each other. You can optimize the rendering under the rendering option.
Now it’s your turn!
Take the time to apply what we’ve learned yourself by doing one or two of the exercises of module 4.
Attention
Check out the wiki article for detailed, step-by-step tutorials on how to use the different features of the styling panel.
You can also read further in the article “Labeling and text hierarchy in cartography” by Axis Maps.