4

I'd like to sum up values from a point layer in my polygon layer from points lying within the polygon. I only found it with the processing toolbox, but that creates a new layer. But I just want to make a new field in my polygon layer that updates when I place a new point. My case: I have a polygon layer with many forests to plant and I want to calculate the number of trees to plant. I have the number in te polygons and in de point layer (tree clusters within the forest polygon). But I need to subtract the number of the (tree clusters) in the polygons. I tried something like this to get the amount of tree clusters in the polygon, but it did not work:

aggregate( layer:='Aanplant_punt_v01', aggregate:='sum', expression:='amount', filter:= contains($geometry, geometry(@parent)))

I do not know if I'm thinking in the right direction.

enter image description here

1 Answer 1

5

your expression should be as follows:

aggregate( layer:='Aanplant_punt_v01', aggregate:='sum',
expression:="amount", filter:= within($geometry, geometry(@parent)))

the expression is a field and must be in double quotations, and the filter must be within, since your parentlayer is the polygon layer

1
  • Waaw super, thank you for the quick response. It works (I was almost there ;-) )
    – Jonathan
    Commented Jun 21, 2023 at 8:44

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.