Geometry / geography woes

Regina Obe lr at pcorp.us
Tue Sep 9 10:05:41 PDT 2025


Your smaller polygon is not within the larger one.  If it was then this would return true

 

SELECT ST_Intersects(ST_GeomFromText('POLYGON((-77.933927810506 48.584377886263184,-77.74471476703403 48.69534746901027,-77.69284285304693 48.71525447165988,-77.99039086603969 48.53485501013662,-77.933927810506 48.584377886263184))', 4326)::geography, ST_GeomFromText('POLYGON((-81.1755551313531 46.64525933571578,-81.50518756520556 47.21802525065504,-81.6706742747649 47.82323694299835,-81.6602226284047 48.438637358868554,-81.46784223247613 49.04081439308046,-81.09452004412593 49.60598066574395,-80.54928811996326 50.110912115887594,-79.84994871352842 50.53403375725974,-79.02318022750863 50.85659915226637,-78.10377843647761 51.06386274945413,-77.13291403765557 51.14610652092342,-76.15549659681517 51.09937193283258,-75.21696581007667 50.925776760111056,-74.42324583717638 50.655006343959805,-81.12758032107652 46.593233077736336,-81.1755551313531 46.64525933571578))',4326)::geography);

 

And it returns false.  Your ST_Within compare in planar space is invalid as it's treating the surfaces as planar.

 

If you segmentize your geographies you will see the smaller is not within the larger.

 

Here is what you get segmentizing in spheroidal space

SELECT ST_Segmentize(ST_GeomFromText('POLYGON((-77.933927810506 48.584377886263184,-77.74471476703403 48.69534746901027,-77.69284285304693 48.71525447165988,-77.99039086603969 48.53485501013662,-77.933927810506 48.584377886263184))', 4326)::geography, 1000)

UNION ALL

SELECT ST_Segmentize(ST_GeomFromText('POLYGON((-81.1755551313531 46.64525933571578,-81.50518756520556 47.21802525065504,-81.6706742747649 47.82323694299835,-81.6602226284047 48.438637358868554,-81.46784223247613 49.04081439308046,-81.09452004412593 49.60598066574395,-80.54928811996326 50.110912115887594,-79.84994871352842 50.53403375725974,-79.02318022750863 50.85659915226637,-78.10377843647761 51.06386274945413,-77.13291403765557 51.14610652092342,-76.15549659681517 51.09937193283258,-75.21696581007667 50.925776760111056,-74.42324583717638 50.655006343959805,-81.12758032107652 46.593233077736336,-81.1755551313531 46.64525933571578))',4326)::geography, 1000);

 



 

Here is your planar:

 

 

SELECT ST_GeomFromText('POLYGON((-77.933927810506 48.584377886263184,-77.74471476703403 48.69534746901027,-77.69284285304693 48.71525447165988,-77.99039086603969 48.53485501013662,-77.933927810506 48.584377886263184))', 4326)::geography

UNION ALL

SELECT ST_GeomFromText('POLYGON((-81.1755551313531 46.64525933571578,-81.50518756520556 47.21802525065504,-81.6706742747649 47.82323694299835,-81.6602226284047 48.438637358868554,-81.46784223247613 49.04081439308046,-81.09452004412593 49.60598066574395,-80.54928811996326 50.110912115887594,-79.84994871352842 50.53403375725974,-79.02318022750863 50.85659915226637,-78.10377843647761 51.06386274945413,-77.13291403765557 51.14610652092342,-76.15549659681517 51.09937193283258,-75.21696581007667 50.925776760111056,-74.42324583717638 50.655006343959805,-81.12758032107652 46.593233077736336,-81.1755551313531 46.64525933571578))',4326)::geography;

 



 

 

 

> -----Original Message-----

> From: nikolai.berkoff via postgis-users <postgis-users at lists.osgeo.org>

> Sent: Tuesday, September 9, 2025 7:36 AM

> To: postgis-users at lists.osgeo.org

> Subject: Geometry / geography woes

> 

> Hi,

> 

> I work for a conservation NGO and we deal with lots of species ranges.

> 

> We have a complicated full geometry (SRID 4326)

>  <https://www.iucnredlist.org/species/22733619/139214707> https://www.iucnredlist.org/species/22733619/139214707 that we have

> ST_Subdivided.  We notice a large difference between the geographical

> distance from a point (-77 48) to the full geometry and to nearest subdiveded

> geometry.

> 

> Here is a toy example with two polygon geometries, one large and the other

> small and a point  <https://wktmap.com/?771d2fc9> https://wktmap.com/?771d2fc9 . First the geographical

> distance from the point to the large geometry:

> 

> SELECT ST_Distance(ST_SetSRID(ST_MakePoint(-77, 48),4326)::geography,

> ST_GeomFromText('POLYGON((-81.1755551313531 46.64525933571578,-

> 81.50518756520556 47.21802525065504,-81.6706742747649

> 47.82323694299835,-81.6602226284047 48.438637358868554,-

> 81.46784223247613 49.04081439308046,-81.09452004412593

> 49.60598066574395,-80.54928811996326 50.110912115887594,-

> 79.84994871352842 50.53403375725974,-79.02318022750863

> 50.85659915226637,-78.10377843647761 51.06386274945413,-

> 77.13291403765557 51.14610652092342,-76.15549659681517

> 51.09937193283258,-75.21696581007667 50.925776760111056,-

> 74.42324583717638 50.655006343959805,-81.12758032107652

> 46.593233077736336,-81.1755551313531

> 46.64525933571578))',4326)::geography);

> 

>    st_distance

> 

> -----------------

>  100757.06933552

> 

> 

> next the geographical distance from the point to the small geometry

> 

> SELECT ST_Distance(ST_SetSRID(ST_MakePoint(-77, 48),4326)::geography,

> ST_GeomFromText('POLYGON((-77.933927810506 48.584377886263184,-

> 77.74471476703403 48.69534746901027,-77.69284285304693

> 48.71525447165988,-77.99039086603969 48.53485501013662,-

> 77.933927810506 48.584377886263184))', 4326)::geography);

>   st_distance

> 

> ----------------

>  93442.14463111

> 

> 

> finally, showing the the small geometry is fully within the large geometry

> 

> SELECT ST_Within(ST_GeomFromText('POLYGON((-77.933927810506

> 48.584377886263184,-77.74471476703403 48.69534746901027,-

> 77.69284285304693 48.71525447165988,-77.99039086603969

> 48.53485501013662,-77.933927810506 48.584377886263184))', 4326),

> ST_GeomFromText('POLYGON((-81.1755551313531 46.64525933571578,-

> 81.50518756520556 47.21802525065504,-81.6706742747649

> 47.82323694299835,-81.6602226284047 48.438637358868554,-

> 81.46784223247613 49.04081439308046,-81.09452004412593

> 49.60598066574395,-80.54928811996326 50.110912115887594,-

> 79.84994871352842 50.53403375725974,-79.02318022750863

> 50.85659915226637,-78.10377843647761 51.06386274945413,-

> 77.13291403765557 51.14610652092342,-76.15549659681517

> 51.09937193283258,-75.21696581007667 50.925776760111056,-

> 74.42324583717638 50.655006343959805,-81.12758032107652

> 46.593233077736336,-81.1755551313531 46.64525933571578))',4326));

> st_within

> 

> -----------

>  t

> 

> 

> Why is the geographical distance to the point and the geometry increasing

> when we are only making the geometry bigger?  Surely as the geometry gets

> bigger it should get nearer to the point?

> 

> Thank you very much!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20250909/dc705a6b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 83014 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20250909/dc705a6b/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 83131 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20250909/dc705a6b/attachment-0001.png>


More information about the postgis-users mailing list