In this post, we’ll look at how to make the label sizes dependent on a field in the attribute table of the layer.
Assume we have a large file, such as a world limits polygon type layer, that we want to label with the names of the countries.
We do not want the labels to look like that.
Instead we want this.
Lets see how we can achieve this.
- Go to the Layer Proprieties (right-click it in the Layers Panel > Proprieties) and navigate to the Labels TAB.
- Select the labeling method > Single Labels.
- Next, select the attribute table field to use for labeling. In this case, we’ll go with the one that saves the names of the world’s countries.
- Choose a Font and a Style.
- For the Size, go to the Data defined override function. This function overwrites the labeling settings by using attribute table entries or expressions based on them.
- By selecting the Edit option, the Expression String Builder opens. In this section, we will write an expression that will allow us to label the world counties while considering the area values stored in the Shape_Area field.
- The expression will be as follow:
scale_linear(“Shape_Area”, minimum(“Shape_Area”), maximum(“Shape_Area”), 1, 100)
- This function transforms a given value from an input domain to an output range using linear interpolation. More specifically, the function scales the names of world countries to a font size between 1 and 100 by taking into consideration the minimum and maximum area values (stored in the Shape Area field).
- Click Ok.
- The dialog closes and the Data defined override button change its appearance meaning that the rule is taken into consideration while labeling.
- Click OK. The Layer Proprieties closes. The result should look like in the following image.
High quality and professional training
For more information check:
- QGIS Documentation – 188.8.131.52. Using data–defined override for labeling
- QGIS Documentation – 184.108.40.206. scale_linear
Check Marks Credits: https://www.freepik.com/free-vector/flat-check-mark-cross-stickers_18141294.htm