I have a dataset of around 20,000 points in a point layer and a polygon layer with a few hundred polygons. Some of the points lie inside the polygons, others do not. I'd like to label every point as either in or out of the polygon, separately in the attribute table of the points layer. Can anyone please advise?
Without any plugins you can use
within($geometry,aggregate('Polygons','collect',$geometry)) = 1
for labels inside the Polygon and
within($geometry,aggregate('Polygons','collect',$geometry)) = 0
for labels outside the Polygon as your Rule. Replace
'Polygons' with the layername of your polygons.
Set up two rules. First one for points inside the polygons:
geomwithin( 'polygons','$geometry') is not null
Second one for points outside the polygons:
geomwithin( 'polygons','$geometry') is null
'polygons' is the name of the polygonlayer. If you want to label them with different attributes, just choose different
label with fields.
In the layer properties of the point layer, rendering tab, show label parameter :
not contains(geometry(get_feature('polygon layer name', 'field name', 'value')), point_on_surface( $geometry))
In my case, this allows me to show label of the red dots if the value of a certain field in the polygon layer is equal to 50 and not 59 .
This works in QGIS 3.14 with no particular plugins.
There may be a way to select all the polygons (get rid of the field name/value parameters) but I don't know how.