<div dir="ltr"><div dir="ltr">Laurent and list,</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Nov 4, 2025 at 4:17 AM celati Laurent via QGIS-User <<a href="mailto:qgis-user@lists.osgeo.org">qgis-user@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Dear all, </div><div><br></div><div>A few weeks ago, I posted an initial message:</div><br><a href="https://lists.osgeo.org/pipermail/qgis-user/2025-October/055789.html" target="_blank">https://lists.osgeo.org/pipermail/qgis-user/2025-October/055789.html</a><br><br>But after further thought, I'm creating a new one to provide additional inputs/clarification.<br>As a reminder, my goal is to find a method/tool to compare the similarity/dissimilarity between two polygonal vector layers consisting of multiple features. In my use case, this comparison concerns a polygonal layer resulting from photo-interpretation work (modeling of large physiognomic units/habitats). I reattached a screenshot; this layer appears in blue.<br>The other polygonal vector layer is a polygonal vector layer resulting from a segmentation process (using an OTB tool available via QGIS). (It is yellow in the attached screenshot):<br><br><img src="cid:ii_mhkj5ijx0" alt="image.png" width="578" height="277"><br><br>In my previous post, I mentioned a possible way for one similarity indicator: "for each photo-interpreted feature/polygon, calculate the percentage (%) of area covered by the feature from the segmentation layer that has the highest overlap."<br>To be more specific, in the example in the screenshot, it could be:<br>"for feature number 11 (blue) from the photo-interpretation layer, I would like to know the proportion of the area covered by the feature from the segmentation layer that has the highest overlap with this feature 11 (in this specific case, it is probably feature 42 in yellow)."<br>This could be: area of feature 42 overlapping with feature 11 / total area of feature 11.<br><br>But after further thought, I think this is insufficient. That i need to go a little further.<br><br>Regarding these methods for quantifying the accuracy of a segmentation/fidelity to photo-interpretation. Regarding the level/degree of similarity, I think i should integrate a "bi-similarity" aspect/logic: using an approach based <b>on pairs</b> of the most overlapping polygons:<br><br><b>step 1</b><br>- For each polygon feature in the input layer, retrieve the ID and geometry of the polygon from the segmentation layer that has the highest overlap. Calculate the overlap rate.<br>(e.g., surface area of feature 42 overlapping with feature 11 / <b>total surface area of feature 11</b>).<br><b><br>Step 2:</b><br>- Once this first indicator is calculated, perform the calculation for the same pair/sequence of polygons calculated in step 1: perform the same calculation but this time on the total surface area of feature 42 (polygon from the segmentation).<br>(e.g., surface area of feature 42 overlapping with feature 11 /<b> total surface area of feature 42</b>).<br><br><b>Step 1/2 variant:</b><br>I was thinking that a one-step variant/synthesis/summary of steps 1 and 2 could be:<br>- (e.g., surface area of feature 42 overlapping with feature 11 / <b>total surface area constituted by feature 11 AND feature 42).</b>?<br></div></div></blockquote><div><br></div><div>If you look at your three steps above, the numerator is always the same - the surface area of feature 42 overlapping with feature 11.  In PostGIS you will want the area of the intersection, something like this:</div><div><br></div><div>SELECT ...,ST_Area(ST_Intersection(interp.geom,segment.geom) as overlap FROM ...</div><div><br></div><div>You can read about these two predicates here:</div><div><br></div><div><a href="https://postgis.net/docs/ST_Intersection.html">https://postgis.net/docs/ST_Intersection.html</a></div><div><a href="https://postgis.net/docs/ST_Area.html">https://postgis.net/docs/ST_Area.html</a></div><div><br></div><div>In your WHERE clause you can use ST_Intersects() to narrow your search to all polygons that intersect with each other, something like</div><div><br></div><div>WHERE ST_Intersects(interp.geom,segment.geom) ...</div><div><br></div><div>Read about that here:</div><div><br></div><div><a href="https://postgis.net/docs/ST_Intersection.html">https://postgis.net/docs/ST_Intersection.html</a></div><div><br></div><div>Along with that core, you can add the total surface area of the interpreted and segmented layers to the SELECT clause, something like:</div><div><br></div><div><div>SELECT ...,ST_Area(ST_Intersection(interp.geom,segment.geom) as overlap_area, ST_Area(interp.geom) as interpreted_area, ST_Area(segment.geom) segmented_area, (ST_Area(interp.geom) + ST_Area(segment.geom)) as total_area FROM ...</div></div><div><br></div><div>You can also use division in the expressions in the SELECT clause to do your division for you, something like</div><div><br></div><div>(ST_Area(ST_Intersection(interp.geom,segment.geom) / ST_Area(interp.geom)) as step1_area</div><div><br></div><div>If you're going to do division, it's always good practice to guard against divide-by-zero using a CASE expression, something like:</div><div><br></div><div><div>CASE WHEN ST_Area(interp.geom) = 0 THEN 0 ELSE (ST_Area(ST_Intersection(interp.geom,segment.geom) / ST_Area(interp.geom)) END as step1_area, ...</div><div></div></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><b> Step 3:</b><br>The idea would be, based on steps 1/2, to have a kind of overall score at the layer level. This could be a kind of average/median for all pairs of polygons? Or another metric?</div></div></blockquote><div><br></div><div>Why not just report all three and decide what you want later?  Alternatively you can take the remote sensing kind of approach:</div><div><br></div><div><a href="https://gsp.humboldt.edu/olm/courses/GSP_216/lessons/accuracy/metrics.html">https://gsp.humboldt.edu/olm/courses/GSP_216/lessons/accuracy/metrics.html</a></div></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Chris Hermansen · clhermansen "at" gmail "dot" com<br><br>C'est ma façon de parler.</div></div></div>