3

I am using leader lines for line labels of vector line. I need to connect leader line with the centre of chosen lines (to have anchor point dropdown at the centre of a lines). Leader lines are now connected with a (perhaps?) closest point of chosen line. At pictures below is seen that direction of leader line changes depending on position of label. I need always have leader line at the centre of line. Can it be done? enter image description here

enter image description here

enter image description here

3
  • Choose Centroid in the Label anchor point dropdown (Symbology | Labels | Callouts).
    – geozelot
    Commented Jun 2, 2021 at 9:28
  • It doesn´t work, centroid in Label anchor point refers to position of leader line to label itself, not a line.
    – pazelvak
    Commented Jun 2, 2021 at 9:31
  • Yeah nevermind, it only works for Polygons - I meant the Anchor point dropdown, not the Label anchor point.
    – geozelot
    Commented Jun 2, 2021 at 9:34

1 Answer 1

2

Right now, placement of callout (leader) lines is limited. QGIS 3.20 (out now) will add support for new options to place callout lines:

#3 Next up #QGIS now allows exact, interactive positioning of callout lines using the "move labels/callouts" tool

For the moment, you could create callout lines with Geometry generator. This works only for labels that ware moved manually before, using Move a Label or Diagram so that an auxiliary storage for the position of the label is created.

Also be aware that for line-features, the centroid often is not on the line itself, so better use the mid-point of the line that you can create with line_interpolate_point($geometry,length ($geometry)/2).

Use this expression to create a callout to this point from your labels using Geomtry generator with this expression:

make_line (
    make_point ( 
        "auxiliary_storage_labeling_positionx",  
        "auxiliary_storage_labeling_positiony" 
    ),
    line_interpolate_point(  
        $geometry, 
        length ($geometry)/2
    )
)

Screenshot: blue = line feature; black = automatic callout/leader line; red: leader line created with geometry generator to the centroid; orange: leader line created with the expression from above:

enter image description here

9
  • Thanks. It works. Problem is, I need to use leader lines only for some labels. For majority of them I set labels along the line. Sometimes I move labels along the line a bit (without a leader line). How can I set "offset from feature" and "offset from label area" and to create some margin when leader line is not visible?
    – pazelvak
    Commented Jun 2, 2021 at 10:37
  • I'm not quite sure about your exact settings and what exactly you want to do, maybe you can elaborate or make sample data available that illustrates the problem. However, as mentioned, as of now, it is only a workaround. The functionality itself will be introduced in 3.20.
    – Babel
    Commented Jun 2, 2021 at 10:46
  • I redirected my question to gis.stackexchange.com/questions/398378/…
    – pazelvak
    Commented Jun 2, 2021 at 11:21
  • I'm not sure if I understood what you want to do, but adding a text-buffer would cover the leader-line under an dnear the label.
    – Babel
    Commented Jun 2, 2021 at 11:57
  • It does not work. Is it possible in geometry generator to add azimuth of callout?
    – pazelvak
    Commented Jun 2, 2021 at 14:27

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.