Is it possible to select only one contour line for labelling?
I have numerous labels for each line and I'll prefer to label only the main ones, such as
1000 m and
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
In QGIS 2.6 (maybe earlier versions as well, I don't know) you can do this under the Layer Properties,
Rendering section. About halfway down the list of rendering options is a button that will let you write an expression which will define the list of features that will actually be labeled. Your expression would be something like
"Elevation" IN (1000, 1500). Here's the button (in yellow), I have this one set to only label contours with an elevation value of 32:
One approach would be to load the contour layer and style it. Then load the same layer again and apply a filter (right-click on the layer and go down to 'Filter..') Use a filter expression similar to the one shown in the picture. In my case I wanted major contours at vertical intervals of 50 metres and the field containing the elevation values was called "prop_value".
When the filtered layer showing the major contours has loaded apply contour labels and (if required) strengthen the line style as shown.
The filter expression:
("prop_value" % 50) = 0
will also select contours at vertical intervals of 50 metres. Works with Spatialite databases, not sure about shapefiles.
I'm using this approach wich makes the labeling and display of contourlines by condition quite easy.
I use the "Data defined properties" of the line symbol width and colors of the contourlines with an expression (see screenshot 1) by which you can apply different line widths based on custom conditions and a similar expression for labeling (see screenshot 2).
Just put the needed values to the expressions and that's all.
I.e. if you want to hide contourlines other than 500 m you can use this expression for the datadefined properties of the line symbol:
CASE WHEN Elevation / 500 - floor(Elevation / 500) = 0 then color_rgba(255,255,255,100) else color_rgba(255,255,255,0) end
i.e. for labeling only 500m intervals use this expression for:
CASE WHEN Elevation /500 - floor(Elevation / 500) = 0 THEN Elevation || ' m' END
i.e. for applying different line width use an expression like this for data defined properties:
CASE WHEN Elevation / 100 - floor(Elevation / 100) = 0 THEN 0.25 WHEN Elevation / 50 - floor(Elevation / 50) = 0 THEN 0.15 ELSE 0.1 END
Another convenient expression is
"ELEV" LIKE '%00' (step 100m) or
"ELEV" LIKE '%00' OR "ELEV" LIKE '%50' (step 50m) or
"ELEV" LIKE '%0' (step 10m) etc, where "ELEV" is my data elevation field. The second option works only if 50 is a multiple of interval (10m or 5m...).