10. November 2013
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.
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.
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.
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.
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.