13

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 1500 m

1

4 Answers 4

13

In QGIS 2.6 (maybe earlier versions as well, I don't know) you can do this under the Layer Properties, Labels tab, 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:

enter image description here

13

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.

enter image description here

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.

6

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

screenshot 1 screenshot 2

1
  • @catindri, Mind to check an answer..
    – Kay
    Nov 18, 2014 at 7:48
6

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...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.