1

Working with QGIS modeler, I need to do some arithmetic operations with some polygon areas.

Let's say there are 2 polygons in layer A and layer B. And I'm inputting them into the model using Vector Layer input. And I need to calculate the ratio of area of these 2 polygons. Then I'll use that number in another algorithm.

enter image description here

This is what I thought I could do, but apparently it's not working.

enter image description here

Can anyone help me get around this problem?

0

1 Answer 1

3

Expression:

aggregate( layer:=@poly_a, aggregate:='sum', expression:=$area) / aggregate( layer:=@poly_b, aggregate:='sum', expression:=$area)

Aggregate will sum all polygon areas of each input layer.

I use the output to calculate a column in layer B, just to verify that Calculate Expression is working. enter image description here

1
  • 1
    Yeah, I managed to run it without the Field Calculator. My mistake was thinking there's only 1 polygon in an input layer. Using aggregate makes sense and works. But is there another way with single polygon per layer assumption? Commented May 30 at 18:20

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.