2

I'm working with QGIS 3.16 Hannover under MacOS 10.13 environment. I've got two polygon layers: natural_parks (multiple features) and region (single feature). I want to add a new field to the layer natural_parks that computes the overlapping area of each Natural Park with my region. Is it possible to do so with the field calculator? So far, I've been able to get it by means of a virtual layer, but I want to insert the results into the original layer.

1 Answer 1

3

Sure, you can use this expression in field calculator of your natural_parks layer:

area(intersection($geometry,collect_geometries(overlay_intersects('region',$geometry))))

Explanation: overlay_intersects() will get all geometries of the region layer which intersect with your current natural_parks feature and store them in an array. collect_geometries() will create a single multipolygon out of this array. intersection() will only keep the overlapping part of this multipolygon and your current natural park. area() finally calculates the area of this intersection. So yes, in your case you can simplify the expression since there is only one feature in your regions layer. But I want to keep this answer a little more universal to use.

2
  • I definitely works but, is there any reasonable explanation for a discrepancy between this calculation and the simple $area function? Actually, none of the figures match in those features that fall enterely within the region: e.g. 100637 vs. 100695; 65316 vs. 65340; etc. I know it's not a great deal, but I feel a bit annoyed anyway.
    – jpinilla
    Mar 12, 2021 at 17:35
  • 1
    @JesúsPinilla Yes there is: The area calculated by $area respects both the current project's ellipsoid setting and area unit settings.Calculations using area() are always planimetric in the Spatial Reference System (SRS) of this geometry, and the units of the returned area will match the units for the SRS. This differs from the calculations performed by the $area function, which will perform ellipsoidal calculations based on the project's ellipsoid and area unit settings. (citated from QGIS function help)
    – MrXsquared
    Mar 12, 2021 at 17:43

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.