[GIS] Creating leader lines for moved labels

geometry-generatorlabelingleader-lineqgissymbology

With a lot of help from gis.stackexchange.com I've created leader lines for point symbols. The lines are based on a geometry generator symbology:

Shortening line geometry using expression dialog in QGIS?

enter image description here

Now, I want to implement leader lines for moved labels. It's very importent to me, that the lines start at the center of the labels and end at the point coordinates (or vice versa).

-- Geometry generator:
make_line(
    make_point(label_x, label_y),
    $geometry)

Once again, the lines are covered by the labels:

enter image description here

enter image description here

Is there a way to address the label boxes and shorten the leader lines? I suppose this is quite a tricky question :/

Best Answer

Firstly, this is a really neat solution! I solved this using a database view (a bit of overkill, but it worked).

My suggestion is to use a background and fill on the label.

Or, looking here, you may be able to chain together a buffer and clip type solution.

difference(make_line(make_point( "x" ,  "y" ), $geometry), buffer(make_point( "x" ,  "y" ),1))

I just tested the above, and it works (I have different fields than you, but it proves the point). The use of the geometry generator is really flexible, so you could have the buffer distance a field too, dependent on symbology perhaps?

I'm not sure what's happening with point 'three', but I guess the anchor point is off to the left a bit.

disjoint label leader lines

Related Question