“Data driven labelling gives you the ability to control label placement using data”
In this module, we will look at how you can use data in your attribute table to specify where labels should be placed, how they should be rotated, what font and font size should be used and so on.
Goal: To be able to place labels with pixel perfect precision on your map.
Check your results:
Name | Expectation |
---|---|
New attributes ❗ |
|
label_x_1mil ❗ |
Decimal: 15, 5 |
label_y_1mil ❗ |
Decimal: 15, 5 |
rotation ❗ |
Whole number: 3 |
font ❗ |
Text: 255 |
font_size_1mil ❗ |
Whole number: 3 |
❗ | |
Labelling options ❗ |
|
Formatting: Wrap on character ❗ |
Space (space bar) |
Formatting: Alignment ❗ |
center |
❗ | |
❗ | |
❗ |
When you use a data field rather than an expression, there is a subtle behaviour difference: When using a data field, QGIS will default to the label property set in the user interface if the attribute is null. This means you can explicitly define placement etc. options in the attribute table where they are needed, and fall back to user interface defaults in all other cases.
It should be noted that there is when you use data driven properties it implies that the cartography has been defined for a specific scale. You may have wondered at the naming convention above. It is useful to know what scale the label placements are optimal for. If you are working in a shared database with multiple projects, it is likely you would create several label_x etc. positions - one for every standard map product you produce.
You can 'bootstrap' data driven labelling properties by using the field calculator. For example, you can pre-fill in the font size property to 12. Similarly, you can pre-pin the label_x and label_y positions based on a simple expression.
While data driven labelling has some advantages, if you have pinned your labels you lose a lot in terms of accommodating new layers being added to the map and automatically ensuring that your labels do not cover important information.
Use data driven label positioning sparingly if you can, the other data driven label properties are probably more valuable.
Choose all that apply: data driven labelling:❗
Which of these would pre-pin your label x position to the feature position:❗
Download the sample data for the lesson.