4

In QGIS (3.22) print layout I want to calculate the number of companies in a given map extent as a dynamic text via expression. I am using the Atlas Tool.

However, with the following code I do not get further. The calculated number is always "0".

aggregate( 
'firms',
'count',
intersects($geometry,map_get(item_variables('map1'),'map_extent')))

What's wrong?

enter image description here

0

1 Answer 1

2

You have the intersect function as the expression parameter, rather than the filter.

This expression works for me:

aggregate( 
    layer:='firms',
    aggregate:='count',
    expression:=$id,
    filter:=intersects(
                $geometry,
                map_get(item_variables('Map 1'), 'map_extent')    -- ensure the name of the map is correct
            )
)

Ensure also that your map extent and the layer are the same CRS (or transform one to the other in the expression, using the transform function).

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.