3

I'm working with QGIS 3.16 Hannover.

I've got a single polygon layer National Park and another layer with a 1x1 km grid UTM. In the print composer, I want to include in the legend the number of UTM grid squares that intersect the National Park (all features of UTM with all features of National Park, so I get one number as result). I've built the following code, but it returns 0.

aggregate(
          layer:='UTM', 
          aggregate:='count', 
          expression:='COD1X1', 
          filter:=intersects($geometry, geometry('National Park') 
                            ) 
          )

What's wrong?

1 Answer 1

5

To get the count of all UTM-features that intersect with the current National Park feature:

aggregate(
          layer:='UTM', 
          aggregate:='count', 
          expression:='COD1X1', 
          filter:=intersects($geometry,geometry(@parent)) 
)

To count all UTM-Features that intersect with all National Park features:

aggregate(
          layer:='UTM', 
          aggregate:='count', 
          expression:='COD1X1', 
          filter:=intersects($geometry,aggregate('National Park','collect',$geometry)) 
)
0

Your Answer

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

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