3

I would like to improve the way arrows point to polygons when moving labels. I have some fields with unique numbers associated with each one. When the centroid of a polygon is outside the physical feature, the arrow will be misguiding. How can I improve my expression for the arrow to point to the perimiter of the polygons as illustrated with the blue circles?

enter image description here

CASE 
WHEN 
("auxiliary_storage_labeling_positionx" IS NOT NULL AND "auxiliary_storage_labeling_positiony" IS NOT NULL) THEN make_line(centroid($geometry),make_point("auxiliary_storage_labeling_positionx","auxiliary_storage_labeling_positiony"))
ELSE
NULL
END

EDIT:

Can anything be done to prevent the arrow appearing a second time if the centroid does not sit on the surface of the polygon as shown below?

enter image description here

1 Answer 1

3

You can use difference to cut the arrow by the polygon ($geometry).

In your case, change

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

to

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

[EDIT]

If the centroid is not within the body of polygon, point_on_surface might be more appropriate.

Please try:

difference(make_line(point_on_surface($geometry),
           make_point("auxiliary_storage_labeling_positionx", 
                      "auxiliary_storage_labeling_positiony")), $geometry)
2
  • thanks for answering the above it's made life a lot easier. I've made a slight amendment to the question. Would you spare a minute to see if it is possible? Many thanks
    – James B
    Commented Dec 12, 2018 at 12:40
  • Hi @JamesB Could you try a modified expression in the edited section?
    – Kazuhito
    Commented Dec 12, 2018 at 12:51

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.