8

I have a bunch of linear data (trails) stored in PostGIS and visualized in QGIS for cartographic production. Many trails have switchbacks, and are generally very "weavy", which makes for difficult and often inefficient labeling of trail names. In many cases, the trails won't even label because it cannot find a suitable path, even when using the "curved" placement options:

Curved label options

Missing labels, too curvy:

Missing labels

I've tried simplifying (straightening) the geometry through a PostGIS view to create a sort of "label layer", but this seems inefficient (lots of layers, and doesn't scale well across zoom levels).

Is there a way to take advantage of the internal QGIS Label Expressions to simplify the geometry of the labels only (not the features themselves) to accomplish straighter, simplified labels and achieve a higher level of success and visual appeal for labels?

I was looking under Labels > Value > Expression Dialog > Geometry > Simplify but couldn't figure out a way to include this into the features "name" field in the label expression.

0

1 Answer 1

9

Yes, there is an option to do exactly that in the Labels placement option in QGIS 3.4+ - you can set placement of labels along a generated geometry.

Under the Placement tab, scroll down to 'Geometry generator' and check the box, then change the geometry to Linestring, then enter an expression to simplify your base geometry by the desired factor (here simplify($geometry,20).

See image below - the green line is the original geometry, red line is the generated geometry (I specified it in the symbology), and note that the labels follow the simplified geometry.

enter image description here

3
  • 1
    This is very timely for my needs, thank you. In exploring, I've found simplify_vw works better than simplify for me (removes vertices by area rather than distance, resulting in fewer label over original-geometry clashes) but ymmv. Also noting that the 20 is a tolerance factor in map units (m resp m2) so for autonomous use may need to make this adjust by map scale after finding the right threshold in one's map).
    – Houska
    Commented Mar 13, 2020 at 15:27
  • I've never actually used geometry generator to simplify before so thanks for the really useful tips! That should do it for OP... I also want to add that obviously geom generator is also really useful for label placement if you want to offset or buffer by map units. I use it to place a label along a 45° leader generated from a point to the length of a radius value in the data set. Using gg it's now like a label on a line, much easier to control distance from generated line and point.
    – she_weeds
    Commented Mar 13, 2020 at 21:11
  • Solid! I'd never paid attention to that option. Thanks for highlighting it. Commented Mar 15, 2020 at 1:04

Your Answer

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

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