Labels in QGIS: selective labelling

Because the function „label selected features only“ does not exist anymore in QGIS, a workaround should just label specific features of the shapefile without exporting a new one. For this only the shapefile, which should be labelled, is needed.

Possibility 1 – label certain values with an expression

In QGIS 2.0 you find the setting “data defined/show labels” at Labels -> Rendering -> Label options. For this the labelling must be activated with the certain attribute. With a click on “Edit…” the expression string editor opens, which some of you should know from the field calculator for example.

labeloptions

There you can define the query, which should be used for the labels. For example:

“build_no” > 10

Now only these polygons get labelled, which have a greater value than 10 in the column build_no. Depending on the objects, which should be displayed, also more complex expressions could be used.

expression

Possibility 2 – label specific features with a ‘label’-attribute

It can happen that the features, which should be labelled, have very random attribute values, which cannot be defined very clearly. To display a case like this, a new attribute label was created – defined as type integer with a length of 1. All the features, which should be labelled, get the value 1 when digitizing or afterwards in the attribute table. The expression in the data defined labelling options just has to be changed to

„label“ = 1

Now only these objects will be labelled, which have the value 1 in the field label.

attribute label

For fast entering of the values the field calculator can be used via the attribute table. You just have to select the objects, which should be labelled, and check the option “Only update selected features”. In addition you just update an existing field – in our case the attribute label. The expression “label”=1 is also valid here, because all the features for labelling get the value 1 in the field label and with this all the marked features are set to the certain value.

Optional – Use checkboxes instead of line edit as line widget

If you want to define the feature as “labelled” or “not labelled” just when editing, but without typing a 1 or 0 all the time, the field label can just be defined as checkbox. For this you have to go to the layer properties, tab ‘field’ and there you can change the line widget from line edit to checkbox at the field label. The default values can be left unchanged in this case. If the user checks the checkbox now, the value 1 will be written into the attribute table. If it is uncheck, the object gets the value 0 at the field label.

checkbox as linewidget

When digitizing you now get the checkbox for the fast activating or deactivating of the label for this feature. You can also use this checkbox in the attribute table by double clicking on the field. Of course you just can set features to 1 or 0 with the field calculator without checking numerous checkboxes. Depending on the size of the dataset and the workflow of digitizing, these steps can speed up your work.

checkbox @new feature

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Adamu El-Oji
10 years ago

Thanks for that bit of information. Pls this version 2.0 what are conditions for downloading it. I have tried downloading 1.8 but only adverts are appearing.
Thanks
El-Oji

Riccardo
Admin
10 years ago
Reply to  Adamu El-Oji

use this link for downloading qgis 2.0 for windows: http://qgis.org/en/site/forusers/download.html

Jorge
Jorge
4 years ago

Im looking for a way to omit certain labels depending on their lenght. For instance, I do no want to see labels that are longer than 5 characters. How can I access a labels length in the field calculator.

I been playing along the line of:

CASE
WHEN “ROUTE_ID” $length > 5 THEN O
ELSE 1
END

How can I correctly do this?