4

I have two layers, one with points that I have set a label on and another with polygons which I would like to use to block the labeling of the points. According to this old answer to Avoiding labeling features if overlapped by another layer in QGIS? I could use the blocking of labeling option of the polygon layer, but this only works partially.

With "No labels":

No labels

With "Blocking":

Blocking

Is this a bug or have I understood the option of "Blocking" wrong? (What other option than remove the points under the polygon do I have?)

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
axel_ande
  • 2,024
  • 13
  • 25

1 Answers1

8

If you want to block completely (hide) the labels under the polygon, you can use the following formula under point label tab -> Render -> Show label -> Edit, and write the following expression:

enter image description here

case
when intersection( $geometry, geometry(get_feature( 'PolyBlock', 'id',0))) then 0
else 1
end

Where 'PolyBlock' is the name of the polygon layer in the layer tree, and 'id' equal 0 is the id field which has the value 0 or the value exists for the target polygon, which you want to use it to hide the labels of the points.

Here is the results

enter image description here

ahmadhanb
  • 40,826
  • 5
  • 51
  • 105