Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there a way to interrupt a contour line beneath an elevation label?

enter image description here

share|improve this question
ArcGIS? QGIS? Custom? – Ragi Yaser Burhum Mar 5 '13 at 3:36
I use qgis for the contour labeling – MAP Mar 5 '13 at 8:37
Would you accept an answer that requires PostGIS? – Scro Mar 5 '13 at 15:01
unfortunatly: no :) But, is there a way to solve the problem with PostGIS? – MAP Mar 5 '13 at 18:53

5 Answers 5

up vote 14 down vote accepted

Yes, doable. Normally I'd suggest a partially transparent buffer, but I see why you want to do this cartographically.

This could be slow, and you need to manually decide where you want the labels to go - but cartographically speaking, that's not a bad thing!

Here's a screenshot...

As you can see, no buffers. The raster underneath is unaffected. I've included thinner intermediate contour lines, and styled them so they're only shown when ELEV % 50 <>0

example of interrupted contour lines

I've done this in QGIS 2.12 ... your mileage may vary with earlier versions.

I assume here you have an "ELEV" field on each contour line.

Segmentize the contour lines

1) Use processing and the GRASS algorithm v.split.length to split your contours into segments of equal length. You need to choose a length which will be close to the size of your label in map units, assuming you're using meters. Here I used 200m.

Be careful with this as it will make your file much, much larger (note the feature counts in the screenshot).

To get around this, you might want to generate only those contours lines you wish to style (e.g. every 50 or 100 meters) to avoid processing all the intermediate contour lines.

2) To this layer, add a 1 digit integer field called showLabel. Default to 0 or NULL.

3) Change the label to only show on a segment where this field is set to 1. Use this for the label text expression...

if ( "showlabel" is not null, "ELEV", "")

I think if(expression,true-value,false-value) is fairly new; if using an older version, you can use CASE-ELSE

4) Change the line style so the fixed length segments are all drawn, except those segments where the label is displayed. So use Rule-Based rendering with two rules

Rule 1: "showLabel" is null
Black, 0% transparent

Rule 2: "showLabel" is not null
Any colour, 100% transparent

Now, all contours will show by default, but no labels.

Manually edit segments where you want to show labels

Go into edit mode and manually select the segments where you want the contour values to display, and set the value of showLabel to 1 for the selected features. You can use Ctrl-select (on Ubuntu/Win, Cmd-Ctrl-Click on Mac?) to multi-select segments to speed things up.

This should now 'clip' the contours where you want the labels to show, and the labels will show in the gaps.

In this case, my label settings were:-

CRS: EPSG 27700 (Local UTM for UK, in meters)
Text size: 50 map units
Placement: Parallel, On Line

Hope that helps!

share|improve this answer
Nice approach! Works very fine! Thanks! – MAP Nov 18 at 15:18
This is the only one fully working solution I can imagine. Very painful though if there are many labels, I can't imagine doing all my groundwater heads maps (thousands per year) this way. Would be great if in the future this is achievable through style - as the best would be custom line pattern and label repeat + offset. – Miro Nov 19 at 0:02

I use the "Buffer" option on the "Label setting" tab. (Using the labels button, not the old labels option on the layer properties dialog.) This does not wipe out the contour line, as I imagine you are wanting to do, but it does make the label legible.

share|improve this answer
I never thought of it before, but it would be convenient if instead of assigning a color for the buffer, you could choose to apply it as a 'knockout' to selected layers. – Scro Feb 25 '13 at 22:01
The latest version of QGIS has transparent buffers so you can reduce the impact on other parts of the map. – Nathan W Feb 25 '13 at 22:59
@MAP A knockout erases the pixels beneath it. If that were an option, in this case you would choose to knockout the contour layer. – Scro Feb 26 '13 at 11:41
knockout - the esri term is "masking"… – mike Feb 26 '13 at 19:47
@MAP - Sponsor a developer, or submit a feature request and wait on the benevolence of others. :) – Scro Feb 27 '13 at 23:02

I think the closest it can get with current QGIS abilities is to use halo (or background) effect with color sourced from table which will be based on the elevation value and color scheme same as used for underlying grid. Of course this would not take into account hillshade and everything else below the halo in the map. Random color example: random color for halo effect of labels With some bit of code this could be rewritten as function to reflect grid color.

In theory it should be possible to use custom line pattern and label repeat + offset. Unfortunately there is no label offset setting.

  • after some testing it is impossible to force QGIS to be strict with placing the labels in exact interval and nowhere else (+ missing starting offset anyway)
  • it is impossible to create custom line pattern with zero mm for space to have starting offset like 20 line - 10 space - 70 line - 0 space - so the label would be placed every 100mm with 30mm offset at the beginning - meaning label would be in the middle of every 10mm hole.

enter image description here

share|improve this answer

Do you remember this thread Martin? The only way I can think of to get near to a solution to your problem would be to overlay your contour layer with a clipped contour layer, use this for labelling and change the line colour to something neutral that would mask the contours under the labels, one hopes without being too intrusive. N.

Added later: it might be worth looking at this thread too, the second answer. Perhaps breaking the contour lines might be an answer, perhaps using the buffer layer used to clip the contours?

share|improve this answer

ESRI blog entry:

Variable-depth masking for contour labels involves three steps:

1creating annotation from the labels, 2using the Feature Outline Masks tool to create masks, and 3using the Advanced Drawing Options > Masking settings to specify which layers the masks will mask out.

share|improve this answer
This shows how it could be implemented, but it doesn't really answer the question. – underdark Mar 5 '13 at 21:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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