27

I want to orient my elevation labels uphill.

Is that possible?

I'm currently using the labeling tool from QGIS (not that one in layer settings). I want the labels curved and uphill oriented (and I would like to define how regularly the numbers are displayed). It's all for a print-map.

2

6 Answers 6

27
+50

Here we go then, a method to get some control over contour label placement, see the picture.

The first thing I did was to load the contours. Next, on a new line shapefile, I drew a line from the top of the hill to the bottom (the labels in the picture are aligned with this). I then buffered the line and used the buffer to clip the contour layer. After that I loaded the clipped contours over the contour layer, set the symbology so that the little lines didn't render, and labelled the clipped layer using the new labelling system.

In the example shown I only used one straight line, but of course it would be possible to use polylines too, to produce better placed labels.

Oh, you only need a small buffer value, 50 metres I think I used in the example, even this might have been greater than strictly necessary.

enter image description here

7
  • Creative method. I might borrow this idea for future maps. Jun 11, 2012 at 16:45
  • 5
    Looks nice, very good idea, Nick! But it sounds like a lot of work to do for a 1000km² area with hundreds of hills and mountains... :)
    – MartinMap
    Jun 11, 2012 at 17:12
  • 1
    Bit of a dirty hack, don't you think? :)
    – blah238
    Jun 11, 2012 at 19:43
  • 1
    Yup! But that's a compliment in my book :) Yes, it would be a fair amount of work Martin, but quicker than shifting point labels about I think. You could draw lots of lines for buffering in the same layer and as I mentioned before they wouldn't have to be straight. It wouldn't be a good idea to cross them though, I think. Nick.
    – nhopton
    Jun 11, 2012 at 19:55
  • This,method combined with Virtual layers can provide a way interactive way of setting the label along a line. Dec 5, 2017 at 16:40
7

Using parallel placement together with "bellow line" and "line orientation dependent position", I managed to put the labels on the uphill side always.

enter image description here

enter image description here

Curved placement currently seems to ignore line orientation though. (I reported the behavior.)

Also, it doesn't seem possible to achieve upside-down labels, if you were aiming for that.

5
  • 1
    orientation is how you know where "uphill" is relative to the contour, even if the labels are upside-down.
    – Mike T
    Jun 9, 2012 at 21:53
  • 2
    Thanks! But its not working very well. The orientation is still orientated to the line angle, not the to the uphill side like 1700m and 1900m or the contour numbers on the hills on the left side. But thanks!
    – MartinMap
    Jun 10, 2012 at 6:53
  • @MikeToews I'm aware of that but currently it doesn't seem possible to create upside-down labels currently (as I mentioned in the answer).
    – underdark
    Jun 10, 2012 at 12:12
  • 'Rules' is too strong a word, but there are conventions about the labelling of lines and the new labelling system does a good job of respecting these. I think if you wanted to select where on the line the labels appear you would have to break the lines into appropriate sections. Nick.
    – nhopton
    Jun 11, 2012 at 12:24
  • There might be another way of handling contour label placement, let me think about this.
    – nhopton
    Jun 11, 2012 at 12:34
6

What you could do is to make a point file from the contours with an attribute of the elevation (You can do this using any profile from line tool). Then add in the point the aspect value (You will need the aspect raster but that is easy to produce) and finally rotate the elevation label in the points according to the aspect (in fact it will need to be 180 degrees + aspect, because aspect is the downhill direction). You can style the points so they don't show. Hope this helps, it strongly depends on the details of your data, if the aspect doesn't match the contour direction it can be quite annoying.

1
  • 1
    (+1) Clever approach--and general enough to work with many GISes, and very flexible, too. (Unfortunately this solution does not address the requirement that labels curve with the contours.) Welcome to our site!
    – whuber
    Jun 11, 2012 at 12:50
3

Picking up Alexandre Netos idea to use a Geometry Generator (GG) for contour labelling (https://twitter.com/AlexNetoGeo/status/1333987969414393856), I managed to enhance the GG code to receive uphill orientation if the scratch lines (Layer "labels") are drawn in uphill direction. Simply enable Geometry Generator for label placement and enter the following code:

collect_geometries( aggregate(
  'labels', -- layer
  'array_agg', -- agregate
  with_variable('geom',intersection(buffer($geometry, 50),geometry(@parent)),
      if(distance(start_point(@geom), $geometry) > distance(start_point(@geom),offset_curve($geometry,50)), @geom,reverse(@geom))),
  intersects(
    $geometry,
    geometry(@parent)) -- filter
))

Don't forget to enable "Show upside-down labels" and the Feature option "Label every part of multi-part features".

2
  • If the contour lines are created using the GDAL processing tool, you don't need the extra logic to make the uphill \ downhill labels work. All you need is to allow upside-down labels: always. Dec 23, 2020 at 1:11
  • @AlexandreNeto good to know, thanks! But I got my contours from a GeoScience Software named „PETREL“, where the direction is sometimes wrong.
    – christoph
    Dec 23, 2020 at 5:13
2

Often, contour line vertices are capture in such a way that the uphill is always at the same side of the line. Maybe it is the case of your data...

1
  • 1
    That seems to be the case for QGIS Contour plugin. But that still leaves the question of how to handle the labels.
    – underdark
    Jun 9, 2012 at 18:17
2

I am assuming the questioner wants the contour labels facing uphill, rather than being placed on the uphill side of the contour.

In QGIS 3.2, go to

  • Layer -> Properties...,
  • tab Labeling
  • sub-tab Rendering

and select Show upside down labels = always. Without this, QGIS will refuse to print labels upside down, and you'll end up with a mix of orientations.

If you find that the labels are all the wrong way up, you can use the Reverse line direction tool from the Processing Toolbox.

Note that this assumes that all contours in the layer are oriented the same way. This should be the case if the Contour tool in QGIS has been used (which calls gdal_contour).

There is a tutorial video on Klas Karlsson YouTube channel: https://www.youtube.com/watch?v=-xzoVF7Z7u0 (labeling begins at 5:16)

2
  • Instead of the Reverse line direction tool, you can use reverse($geometry) in the geometry generator field to do the reversing on the fly. (That’s the approach in the video.) Jun 4, 2020 at 17:14
  • This is by far the best and most helpful answer to the question without any tedious workaround. Seems to work fine!
    – Vincent
    Apr 15 at 10:45

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.