[postgis-tickets] [PostGIS] #4081: ST_DWithin using spheroid does not calculate distance properly for geography

PostGIS trac at osgeo.org
Tue May 8 14:01:10 PDT 2018


#4081: ST_DWithin using spheroid does not calculate distance properly for
geography
---------------------+---------------------------
 Reporter:  amc6     |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  medium   |  Milestone:  PostGIS 2.4.5
Component:  postgis  |    Version:  2.4.x
 Keywords:           |
---------------------+---------------------------
 It appears that ST_DWithin is not properly calculating distance for
 geography points. Or at the very least, it is not calculating distance the
 same as ST_Distance does. (When forced to use a sphere, both ST_DWithin
 and ST_Distance match.) I've included a query below to demonstrate the
 problem. It includes several different calculations to illustrate what is
 going on, but I will summarize the key points here:

 The points are Point(1 2) and Point(1 1). According to a 3rd party
 calculator (http://www.flymicro.com/records/distcalc.cfm) the distance
 between these two points is 110575 meters and this matches with the
 calculation produced by ST_Distance. ST_DWithin appears to be calculating
 a value of around 111155.5 meters, which does not match the value
 calculated by ST_Distance with either a spheroid or sphere. However, the
 function _ST_DWithinUncached appears to be calculating the correct value
 of 110575.

 Query:
 {{{
 select ST_asEWKT(a), ST_asEWKT(b), pg_typeof(a), pg_typeof(b),
 ST_Distance(a, b, true) as dist_true, ST_Distance(a, b, false) as
 dist_false,
 ST_DWithin(a, b, 111155.5, true) as within_111155_5_true, ST_DWithin(a, b,
 111155.6, true) as within_111155_6_true,
 ST_DWithin(a, b, 111195.079, false) as within_111195_079_false,
 ST_DWithin(a, b, 111195.08, false) as within_111195_08_false,
 _ST_DWithinUncached(a, b, 110576, true) as within_uncached_110576,
 _ST_DWithinUncached(a, b, 110575, true) as within_uncached_110575,
 _ST_DWithinUncached(a, b, 111195.08, false) as
 within_uncached_111195_08_false, _ST_DWithinUncached(a, b, 111195.079,
 false) as within_uncached_111195_079_false
 from (
         select ST_GeogFromText('SRID=4326;POINT(1.0 2.0)') as a,
 ST_GeogFromText('SRID=4326;POINT(1.0 1.0)') as b
 ) as points
 }}}

 Results:
 {{{
       st_asewkt       |      st_asewkt       | pg_typeof | pg_typeof |
 dist_true    |   dist_false    | within_111155_5_true |
 within_111155_6_true | within_111195_079_false | within_111195_08_false |
 within_uncached_110576 | within_uncached_110575 |
 within_uncached_111195_08_false | within_uncached_111195_079_false
 ----------------------+----------------------+-----------+-----------+-----------------+-----------------+----------------------+----------------------+-------------------------+------------------------+------------------------+------------------------+---------------------------------+----------------------------------
  SRID=4326;POINT(1 2) | SRID=4326;POINT(1 1) | geography | geography |
 110575.06481434 | 111195.07973463 | f                    | t
 | f                       | t                      | t
 | f                      | t                               | f
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4081>
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