The aim of this post is to describe a method for labeling of a subset of features within a layer using new labeling functionality.
Often, we want to label only a few features in a layer. Of course we can export those features to a new layer and label them that way, but that requires creation of additional files and layers within your project. Things will start to get messy fast.
Another approach is to delete unwanted label texts from the attribute table. This either means that you have to duplicate a “name” attribute and then start deleting from the newly created attribute table column or that you actually delete values in the original column. Both approaches are problematic. Either you produce redundancy that gets difficult to maintain (two attributes have to be updated if the name of a feature changes) or you loose information from the attribute table.
The suggested solution
Let me present a different approach using new labeling tools. The idea is based on moving unwanted labels out of view. This approach avoids duplication of features and duplication/deletion of label texts. And this is the workflow:
- Select the features you want to label
- Open attribute table
- If you don’t have label attributes ready yet: Add two type “real” columns called e.g. “label_x” and “label_y”
- Invert the selection (3rd button in attribute table window)
- Open field calculator and fill “label_x” and “label_y” fields of the selected features with 0 values (or any coordinates outside your map extent)
- Close field calculator and attribute table
- Save your edits
- Open the labeling dialog and set “data defined settings” – “x coordinate” and “y coordinate”
- Enable “Label this layer” and specify the label field
If you change your mind about a feature and want to label it later on: Simply delete the values in “label_x” and “label_y” fields (so they read NULL).
This works quite well for me but I’m aware that it’s still not optimal. Another “data defined setting” like “show this label (true/false)” would be more intuitive.
Have you found better solutions to this problem? Please, post them!