I am using the following expression to count and label the number of geometries of a layer (POINTS1_TO_INCLUDE) that intersect with polygons of another layer (POLYGONS):
to_string(
round(array_length(
overlay_intersects(
array_to_string(
array_filter(
@map_layer_ids,@element not in (@layer_id,'POLYGONS_31860b0b_1cc5_4deb_9016_5fa3bb37ba18'))), $id))))
The result is as follows:
As can be seen in the screenshot, the number of geometries of the POINTS1_TO_INCLUDE layer that intersect with the POLYGONS layer are labeled and the geometries POINTS_TO_EXCLUDE layer are excluded from counting.
The objective is to be able to add new layers with any layer name and keep the expression working. Now the expression stops working when I add a new layer, as you can see in the screenshot:
Any idea how to get the expression to work as shown below:
array_filter
is 2 layers, instead of 1. This in turn breaks theoverlay_intersects
function. I'm not aware of any functions in the Expression Builder that will operate on multiple layers without specifying each layer - which is not to say there aren't any. But you might need to look at a different approach.