Geographic Information Systems Asked on March 19, 2021
I’m working with QGIS 3.16 Hannover under MacOS 10.13 environment. I’ve got two polygon layers A
and B
with multiple features in each. I want to calculate, for each feature in layer A
, the percentage of its area that is actually covered by any feature of layer B
. I have built in the field calculator of layer A
the following code, that seems to work in some cases, but definitely doesn’t in others
(area(intersection($geometry, collect_geometries(overlay_intersects('B', $geometry)))))*100/area($geometry)
Any idea of what’s wrong?
I see two cases when this does not work:
To cover both cases, you can use this expression:
coalesce((area(intersection($geometry, buffer(collect_geometries(overlay_intersects('B', $geometry)),0))))*100/area($geometry),0)
Explanation:
coalesce()
will cover the NULL case and insert 0 if no
result is returned by the actual expression.buffer(...,0)
will dissolve the overlapping parts of the multipolygon by a buffer of 0 (workaround since there is no actual dissolve()
function) so will prevent from causing an error in the calculationExample:
Correct answer by MrXsquared on March 19, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP