Is there a way to interrupt a contour line beneath an elevation label?
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
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
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.
To this layer, add a 1 digit integer field called showLabel. Default to 0 or NULL.
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
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!
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.
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: 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 running into the same problem recently I've put together a QGIS Python script to carry out the heavy lifting. The script including some (UK) test data, Readme (Guide) and style sheets used can be found at https://github.com/pjgeng/Contour-Labels
In short the script uses two vector layers as input - the annotated contour layer and a "guides" layer. The latter consists of polylines intersecting the contours at the desired label locations.
The script then works out based on distance between contours and the index contour interval which labels to apply, adds a rotation value to the label points and eventually clips the original contour layer to produce the gaps.
The approach works particularly well should the user need to produce contour maps at differing intervals in the same area (i.e. the guides don't change). A drawback is the inability to change the label position once the script has finished. For this the user would have to adjust the guide lines and rerun the script against the original input. I previously worked with buffers around labels a lot to create the interrupted effect, but this turned out to be aesthetically unpleasant on vector data driven maps.
Unfortunately I can't add any more pictures at this time to document or illustrate the process further.
PS: If using the style layers provided in the repository users may need to "activate" the custom fields for "Rotation", "Show Label" and "Always Show" in the labelling menu. On some installations of QGIS these are applied automatically from the stylesheet - I haven't found out what causes this yet.
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?
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.