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
1 Answer
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:
-
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?– pazelvakCommented 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.– BabelCommented Jun 2, 2021 at 10:46
-
I redirected my question to gis.stackexchange.com/questions/398378/…– pazelvakCommented 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.– BabelCommented Jun 2, 2021 at 11:57
-
It does not work. Is it possible in geometry generator to add azimuth of callout?– pazelvakCommented Jun 2, 2021 at 14:27
Centroid
in the Label anchor point dropdown (Symbology | Labels | Callouts).