2

I am trying to calculate the area ('area' - pink/red colored) of the Layer ('Layer1') within a polygon of a different Layer ('Layer2' - yellow selected). I`ve tried to calculate it, within the layer2 fieldcalculator with the command: geomwithin('Layer1','area') but the calculations are wrong when I control them by calculating by hand. Any ideas?enter image description here

3
  • If you ran a union or intersect of your two layers, recalculated the area fields you could then dump the attribute table into a pivot table for all sorts of analysis. You might look at the Overlap Analysis tool first to see if it gives you what you want. Note, if you have overlapping polygons in either input layer that overlap will be part of the result which could complicate things.
    – John
    Commented Sep 6, 2022 at 13:06
  • You could also clip they selected polygon by the pink polygons and calculate the new area.
    – Binx
    Commented Sep 6, 2022 at 14:45
  • Do they have the same projection? expression may fail if the two layers have different crs.
    – Al rl
    Commented Sep 7, 2022 at 0:13

1 Answer 1

3

There are a lot of methods which come to mind.

Try this first:

Processing -> Toolbox -> Join attributes by location (Summary)

enter image description here

Result:

enter image description here

Edit: Note about dissolving

Depending on the granularity of the data you need you might want to Dissolve the input layer beforehand, so that each region is represented by a single (multipoly) feature. For example, in the picture above, the Region "Italy" is represented by sevverla polygons (due to the islands, for example), so we will have one row per polygon. If, instead, I were to Dissolve on the field "Country", Italy mainland and its islands would become a single multipoly feature, and Join attributes by location (Summary) would yield a single row.

2
  • Well, this would work out, but I have to calculate this for 112 regions. Thats why i am looking for a more automatic solution. Why is the command geomwithin('Layer1','area') not working at this? I clipped the Layer1 to the regions before, so there are no overlapping polygons.
    – lesto
    Commented Sep 7, 2022 at 7:02
  • The reason why I suggested you this method is that it can be seamlessly extended to any number of combinations. If you have 112 regions (I guess meaning overlapping polygons as in "Layer 2" of your original question) and run this command, yuo will get (at least) 112 rows, each with a summary. See the edit about "Dissolve" ;) Commented Sep 7, 2022 at 8:05

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.