<div dir="auto">Very clever.  I will spend time to understand.  Approximate equal sounds very interesting.   I just did intersection.  Expecting a polygon but got partial lines.  Suspect only part of lines of two seemingly the same polygons intersect. Thanks.  </div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, 29 Oct 2025, 17:25 Paul Ramsey, <<a href="mailto:pramsey@cleverelephant.ca">pramsey@cleverelephant.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I would imagine that my little example is a bit error prone, but the classic solution to "do these differently structured things with slightly different coordinates cover basically the same space" is to inspect the ratio  "area(intersection(a, b)) / area(union(a, b))". You can see intuitively how the more the same two polygons are, the closer that ratio will be to 1.0. <div><br></div><div>WITH p AS (<br>  SELECT 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'::geometry AS p1,<br>         'POLYGON((0 0, 10 0, 10 5, 10 10, 0 10, 0 0))'::geometry AS p2,<br>         0.001 AS shift<br>),<br>shifted AS (<br>  SELECT p1, ST_Translate(p2, shift, shift) AS p2, shift<br>  FROM p<br>),<br>areas AS (<br>  SELECT ST_Area(ST_Union(p1, p2, shift/10)) AS area_union,<br>         ST_Area(ST_Intersection(p1, p2, shift/10)) AS area_inter<br>  FROM shifted<br>)<br>SELECT ST_AsText(shifted.p1) AS p1_orig, <br>       ST_AsText(shifted.p2) AS p2_orig, <br>       area_inter/area_union AS ratio<br>FROM areas, shifted;<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 29, 2025 at 10:17 AM Paul Ramsey <<a href="mailto:pramsey@cleverelephant.ca" target="_blank" rel="noreferrer">pramsey@cleverelephant.ca</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Greg isn't passing judgement on how hard your problem is, he's saying you haven't explained it particularly well. Pictures help. Taking a guess at what you mean, here's some SQL that creates two polygons, with slightly different structure, and slightly different coordinates, that describe the same general space in the universe, and then massages them until they pass an equals test.<div><br></div><div>WITH p AS (<br>  SELECT 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'::geometry AS p1,<br>         'POLYGON((0 0, 10 0, 10 5, 10 10, 0 10, 0 0))'::geometry AS p2<br>),<br>shifted AS (<br>  SELECT p1, ST_Translate(p2, 0.0001, 0.0001) AS p2<br>  FROM p<br>),<br>rp AS (<br>  SELECT ST_ReducePrecision(p1,0.1) AS p1,<br>         ST_ReducePrecision(p2,0.1) AS p2<br>  FROM shifted<br>),<br>snap AS (<br>  SELECT ST_Snap(p1,p2,0.1) AS p1, <br>         ST_Snap(p2,p1,0.1) AS p2<br>  FROM rp<br>)<br>SELECT ST_AsText(shifted.p1) AS p1_orig, <br>       ST_AsText(shifted.p2) AS p2_orig, <br>       ST_AsText(snap.p1) AS p1_snap, <br>       ST_AsText(snap.p2) AS p2_snap,<br>       ST_Equals(snap.p1, snap.p2)<br>FROM snap, shifted;<br></div><div><br></div><div>-[ RECORD 1 ]--------------------------------------------------------------------------------------------------<br>p1_orig   | POLYGON((0 0,10 0,10 10,0 10,0 0))<br>p2_orig   | POLYGON((0.0001 0.0001,10.0001 0.0001,10.0001 5.0001,10.0001 10.0001,0.0001 10.0001,0.0001 0.0001))<br>p1_snap   | POLYGON((0 10,10 10,10 5,10 0,0 0,0 10))<br>p2_snap   | POLYGON((0 10,10 10,10 5,10 0,0 0,0 10))<br>st_equals | t<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 29, 2025 at 10:00 AM Shaozhong SHI <<a href="mailto:shishaozhong@gmail.com" target="_blank" rel="noreferrer">shishaozhong@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">This is very challenging.  Take my words for it.  Try on any polygons you created and modified.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 29 Oct 2025 at 14:36, Greg Troxel <<a href="mailto:gdt@lexort.com" target="_blank" rel="noreferrer">gdt@lexort.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Shaozhong SHI <<a href="mailto:shishaozhong@gmail.com" target="_blank" rel="noreferrer">shishaozhong@gmail.com</a>> writes:<br>
<br>
>   Visually, there appears some matching polygons.  Even if two geometries<br>
> represent the same shape visually, they might not be considered equal due<br>
> to tiny differences in precision or metadata.  Have you encountered<br>
> problems of failure of spatial join?  How did you overcome the problems?<br>
> Regards, David<br>
<br>
Could you post your example polygons, and the queries you are using?<br>
Your question is much too open ended.  It even sounds like it might be a<br>
request for help with GIS homework, but it's hard to tell :-)<br>
<br>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>