2

Is there a way to place all labels from three different point based vector layers outside of a boundaries of a separate polygon?

I have three layers of projects sites and want to have them all display outside of the island polygon. I have manually moved a few in the screenshot attached but would like to automate it as there are many project sites across the island. enter image description here

1
  • Good question. What version of QGIS 3 are you using? What tool for the callouts? Would you consider grouping all your points in one single layer? That way it'd be easier to experiment once a proposed solution comes along.
    – user99006
    May 24 at 23:00

1 Answer 1

3

As a possible starting point, you could use Geometry Generator (under the Placement tab for Labels) to move the labels outside the polygon. The following expression will generate a point on the boundary of your polygon (in my case, 'Country'), buffered by a certain amount (in my case, 0.2 degrees) to force it outside. The aggregate and convex hull are to cater for issues with multi-polygons - may not be required in all cases:

enter image description here

Code:

closest_point(
        aggregate(layer:='Country', 
            aggregate:='collect', 
            expression:=exterior_ring(convex_hull(buffer($geometry,0.2)))
    ),$geometry
)

You can then use a very similar expression in the Symbology, by adding a Geometry Generator to the original marker:

enter image description here

Code:

make_line(
    closest_point(
            aggregate(layer:='Country', 
                aggregate:='collect', 
                expression:=exterior_ring(convex_hull(buffer($geometry,0.2)))
        ),$geometry
    ),$geometry
)

This should be able to be extended to multiple point layers, per the original question.

Output on my single point layer looks like the following. Not a perfect solution, but might be a building block:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.