You can use a Label placement defined by Geoemtry Generator. Use it to define a polygon where placements are allowed: inside a buffer around the outer boundary of your polygons (bufferA
), but not inside a buffer around a polygon from another layer, the "label blocking" polygon. Let's call the buffer around this "label blocking" polygon bufferB
. Now you have to clip (difference) from bufferA
the area of bufferB
.
To achieve this, use this expression for label placement, where polygon2
is the name of the layer containing the label blocking polygons and the buffer size of 8000 and 1000 can be changed to suit your needs:
difference (
single_sided_buffer (boundary($geometry), -8000),
collect_geometries (
overlay_nearest (
'polygon2',
buffer ($geometry, 1000),
limit:=10
)))
Screenshot: yellow polygons are labeled in a way to avoid labels where the red polygon from another layer overlaps. The blue polygon is just for visualization purpose and shows the geomtry cretated using Geometry generator with the above expression: it defines the areas where labels are allowed:
Blocking
also (available from the dropdown where you choose the type of label). But unfortunately this literally just blocks the label and doesn't displace it. Though it might be suitable if you are using repeating labels