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). Some natural_parks features lay entrely within the region feature, some lay completely outside and some are only partly within. I want to calculate the areas of the natural_parks features that do not overlap with the region feature, assigning a 0 value for those enterely within. Actually, what I need is calculate the marine area (in hectares) for each natural park. I built the following code in the natural_parks layer with the field calculator, but it doesn't work

case when overlaps($geometry, geometry(get_feature('region', 'id', 1))) = 1 
     then ($area - area(intersection($geometry, geometry(get_feature('region', 'id', 1)))))/10000
     when overlay_disjoint('region') 
     then $area/10000
   else 0 end

What's wrong with my code?


1 Answer 1


Try this:

(area($geometry) - (area(intersection($geometry, geometry(get_feature_by_id('region', 1))))))/10000

If you use area($geometry) instead of $area it will be automatically 0 if its entirely within. The reason is the different calculation method between these functions.


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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