[Qgis-user] Percentage of area overlaped / covered by feature of another layer

chris hermansen clhermansen at gmail.com
Sun Oct 12 17:33:47 PDT 2025


Laurent and list,

On Sun, Oct 12, 2025, 10:27 celati Laurent via QGIS-User <
qgis-user at lists.osgeo.org> wrote:

> Dear all,
>
> I'm working with QGIS and, if necessary, PostGIS.
> I have two vector layers :
>
>  - A first polygonal layer resulting from vectorization work using
> photointerpretation of the aerial imagery (in blue in the attached
> screenshot below).
>  - A second polygonal layer in the same area resulting from segmentation
> of the same aerial imagery (in yellow in the attached screenshot below).
>
> [image: unnamed.png]
>
>
> Each feature in the two layers has a unique identifier (representing
> thanks to labels in the screenshot).
>
> I'd like to be able to produce a small performance indicator of the
> segmentation performs in faithfully matching the photointerpretation. I was
> thinking there's probably something that could be done with geoprocessing
> (union, intersection?) and a area calculation ? An indicator of
> segmentation performance could be: for each photo-interpreted
> feature/polygon, calculate the percentage of the surface area covered by
> the feature in the segmentation layer with the biggest overlap ?
> To be more specific, in the example screenshot, this could be:
> "For feature 11 in photo-interpretation layer (blue), I would like to know
> the percentage of the surface area covered by the feature in the
> segmentation layer that has the highest overlap with this feature 11 (in
> this specific case, it's probably feature 42 in yellow)."
>
> This could be: area of feature 42 overlapping feature 11 / total area of
> feature 11?
>
> I don't know if I'm on the right path. How could we translate/reach this
> needs toward a QGIS and/or PostGIS tool?
>

One way to do this is an intersection of the two polygon layers, using
ST_intersection. This will create a bunch of "sliver" polygons with the ID
pair (for example) and the area of the sliver.  You will want to sum the
area grouping by the two layer ids as in general the boundary on one layer
may be split into several pieces by the boundary on the other layer.

You can put that in a temporary table called slivers.  You don't need the
geometry, just the polygon ids from each layer and the area of
intersection.  Your table might look something like this:

 interp_id | segment_id | area
-----------+------------+------
         1 |          1 |   15
         1 |          2 |  0.2
         1 |          3 |  0.1
         1 |          4 |  0.2
         2 |          1 |  0.2
         2 |          2 |   12
         2 |          3 |  0.1
         2 |          4 |  0.1

Then you can do something like this:

select slivers.interp_id,sum(slivers.area) differentials
from slivers
where slivers.area != (select max(others.area) from slivers as others where
others.interp_id = slivers.interp_id group by slivers.interp_id)

group by slivers.interp_id;

select slivers.interp_id,sum(slivers.area) congruencies
from slivers
where slivers.area = (select max(others.area) from slivers as others where
others.interp_id = slivers.interp_id group by slivers.interp_id)
group by slivers.interp_id;

which would produce something like this:

 interp_id | differentials
-----------+---------------
         1 |           0.5
         2 |           0.4
(2 rows)

 interp_id | congruencies
-----------+--------------
         1 |           15
         2 |           12
(2 rows)

Of course, the above two select statements will produce an error in the
(edge) case where the sum of the bits of non-overlap are exactly equal to
the overlap in area.

You can further join the sum of all areas in each interpreted polygon to
the two selects above if you want to calculate a percent of differentials
and congruencies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20251012/1116767c/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unnamed.png
Type: image/png
Size: 141640 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20251012/1116767c/attachment-0001.png>


More information about the QGIS-User mailing list