2

I used the following link to create labels with leaders, but since I have a polyline layer I used a different expression for the Geometry Generator:

make_line(
  centroid($geometry),
  make_point("auxiliary_storage_labeling_positionx", "auxiliary_storage_labeling_positiony")
)

It appears to work, but looks quite ugly, where some of the leaders go past the geometry centroid as follows:

Example_1

And others fail to reach it:

Example_2

Why does this occur and how can I fix it?

1 Answer 1

3

The centroid of the geometry is basically the centerpoint of the geometry's bounding box. Thus, it can be situated outside of the geometry, especially when it comes to lines. Only for straight lines the centerpoint will be "inside" the geometry.

You could use the middle of the line instead.

3
  • What is the expression to get the middle of the line?
    – user32882
    Commented Feb 18, 2019 at 10:11
  • 1
    @user32882, have you seen this thread Finding middle point (midpoint) of line in QGIS?? It might be something with $length/2.
    – Taras
    Commented Feb 18, 2019 at 10:15
  • 2
    Nevermind, I found it. The expression should be make_line( line_interpolate_point($geometry, $length/2), make_point( "auxiliary_storage_labeling_positionx" , "auxiliary_storage_labeling_positiony" ) )
    – user32882
    Commented Feb 18, 2019 at 10:18

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.