[PostGIS] #5740: ST_DistanceSpheroid doesn't return 0 when one geometry contains the other
PostGIS
trac at osgeo.org
Tue Jun 11 19:35:09 PDT 2024
#5740: ST_DistanceSpheroid doesn't return 0 when one geometry contains the other
-------------------------+---------------------------
Reporter: cdestigter | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.4.3
Component: postgis | Version: 3.4.x
Resolution: | Keywords:
-------------------------+---------------------------
Description changed by cdestigter:
Old description:
> The docs say
>
> > Returns minimum distance in meters between two lon/lat geometries given
> a particular spheroid
>
> Based on this description it seems that any intersection between the two
> geometries to cause the result to be 0 (the minimum distance between the
> geometries is 0 because they overlap)
>
> However, perhaps it actually compares the _edges_ of the geometries and
> so if one geometry contains the other you get a positive number:
>
> {{{
> #!sql
>
> -- touching the edge of the polygon, the result is zero
> => select st_distancespheroid('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
> 0))'::GEOMETRY, 'SRID=4326;POINT(0 0.5)'::geometry);
>
> 0
>
> -- close to the edge, the result is nonzero
> => select st_distancespheroid('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
> 0))'::GEOMETRY, 'SRID=4326;POINT(0.1 0.5)'::geometry);
>
> 11131.528045775543
>
> -- the further you get from the edge, the larger the result
> => select st_distancespheroid('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
> 0))'::GEOMETRY, 'SRID=4326;POINT(0.5 0.5)'::geometry);
>
> 55657.640177233385
>
> }}}
>
> Interestingly, `ST_DistanceSphere` gives the expected result:
>
> {{{
>
> => select st_distancesphere('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
> 0))'::GEOMETRY, 'SRID=4326;POINT(0.5 0.5)'::geometry);
>
> 0
>
> }}}
New description:
The docs say
> Returns minimum distance in meters between two lon/lat geometries given
a particular spheroid
Based on this description it seems that any intersection between the two
geometries should cause the result to be 0 (the minimum distance between
the geometries is 0 because they overlap)
However, it seems that actually compares the _edges_ of the geometries -
if one geometry contains the other you get a positive number:
{{{
#!sql
-- touching the edge of the polygon, the result is zero
=> select st_distancespheroid('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
0))'::GEOMETRY, 'SRID=4326;POINT(0 0.5)'::geometry);
0
-- close to the edge, the result is nonzero
=> select st_distancespheroid('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
0))'::GEOMETRY, 'SRID=4326;POINT(0.1 0.5)'::geometry);
11131.528045775543
-- the further you get from the edge, the larger the result
=> select st_distancespheroid('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
0))'::GEOMETRY, 'SRID=4326;POINT(0.5 0.5)'::geometry);
55657.640177233385
}}}
Interestingly, `ST_DistanceSphere` gives the expected result:
{{{
=> select st_distancesphere('SRID=4326;POLYGON((0 0,0 1,1 1,1 0,0
0))'::GEOMETRY, 'SRID=4326;POINT(0.5 0.5)'::geometry);
0
}}}
--
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5740#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