[PostGIS] #5895: Distance Calculation Issue with `ST_DistanceSphere`
PostGIS
trac at osgeo.org
Sat May 10 21:29:59 PDT 2025
#5895: Distance Calculation Issue with `ST_DistanceSphere`
------------------------------+---------------------
Reporter: giovannicimolin | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone:
Component: postgis | Version: 3.4.x
Resolution: | Keywords:
------------------------------+---------------------
Comment (by robe):
I get the same results sadly even on my last compile of master branch
so I think something is wrong.
{{{
POSTGIS="3.6.0dev 3.5.0-308-g935e23f3c" PGSQL="170" GEOS="3.14.0dev-
CAPI-1.20.0" (compiled against GEOS 3.13.1) SFCGAL="SFCGAL 1.5.2, CGAL
5.6.2, BOOST 1.86.0" PROJ="8.2.1 NETWORK_ENABLED=OFF
URL_ENDPOINT=https://cdn.proj.org
USER_WRITABLE_DIRECTORY=C:\Users\lr\AppData\Local/proj
DATABASE_PATH=C:\ming64gcc81\projects\proj\rel-
proj-8.2.1w64gcc81/share/proj/proj.db" (compiled against PROJ 8.2.1)
GDAL="GDAL 3.9.2, released 2024/08/13" LIBXML="2.12.5" LIBJSON="0.12"
LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)" RASTER
}}}
The ST_DistanceSphere should return the same answer as:
{{{
SELECT ST_Distance(
ST_GeomFromGeoJSON('{
"type": "Polygon",
"coordinates": [
[
[ -93.751932270476971, 32.089230804932349 ],
[ -93.753830066356031, 32.089181143046332 ],
[ -93.753864556452115, 32.090802706180867 ],
[ -93.751940314782857, 32.09084654939128 ],
[ -93.751932270476971, 32.089230804932349 ]
]
]
}')::geography,
ST_GeomFromGeoJSON('{
"type": "Point",
"coordinates": [ 52.41828388240291, 28.68513149020453 ]
}')::geography, false
) AS distance;
}}}
So that's good, they both agree the answer is 0 and I guess both wrong.
I didn't think our logic relied on winding unless it started to after our
change to use geograpiclib
I do note that the geography intersection does come back with POINT EMPTY
for intersecting point
{{{
SELECT ST_AsText(ST_Intersection(
ST_GeomFromGeoJSON('{
"type": "Polygon",
"coordinates": [
[
[ -93.751932270476971, 32.089230804932349 ],
[ -93.753830066356031, 32.089181143046332 ],
[ -93.753864556452115, 32.090802706180867 ],
[ -93.751940314782857, 32.09084654939128 ],
[ -93.751932270476971, 32.089230804932349 ]
]
]
}')::geography,
ST_GeomFromGeoJSON('{
"type": "Point",
"coordinates": [ 52.41828388240291, 28.68513149020453 ]
}')::geography)
) AS intersection;
}}}
and I think the geography ST_Intersection doesn't use geographiclib but
instead projects both geometries to some best srid and then does the
intersection.
@pramsey you have thoughts on this?
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5895#comment:1>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list