[postgis-tickets] [PostGIS] #3448: ST_Distance yields inconsistent results when used in a statement involving multiple Point and Multipolygon Geography pairs

PostGIS trac at osgeo.org
Fri Feb 5 12:32:24 PST 2016


#3448: ST_Distance yields inconsistent results when used in a statement involving
multiple Point and Multipolygon Geography pairs
-------------------------------------------+---------------------------
 Reporter:  ewcz                           |      Owner:  pramsey
     Type:  defect                         |     Status:  new
 Priority:  medium                         |  Milestone:  PostGIS 2.2.2
Component:  postgis                        |    Version:  2.2.x
 Keywords:  ST_Distance, _ST_DistanceTree  |
-------------------------------------------+---------------------------
 The function `ST_Distance` returns inconsistent results when calculating
 the mutual geographical distance of several points with respect to given
 (multi)polygon.

 Using the tables as in the attached minimal example, following SQL
 statement works as expected:

 {{{
 sample=# SELECT N.node_id, P.iid, ST_Distance(P.outline::geography,
 N.location::geography)
 FROM N, P WHERE (N.node_id IN (2) AND P.iid=1);
  node_id | iid |   st_distance
 ---------+-----+------------------
        2 |   1 | 1730626.41376862
 (1 row)
 }}}

 While a similar statement taking into account all three points gives wrong
 distance for the second point, i.e.,
 {{{
 sample=# SELECT N.node_id, P.iid, ST_Distance(P.outline::geography,
 N.location::geography)
 FROM N, P WHERE (N.node_id IN (1,2,3) AND P.iid=1);
  node_id | iid |   st_distance
 ---------+-----+------------------
        1 |   1 | 1951140.06556506
        2 |   1 |                0
        3 |   1 | 1727662.98350914
 (3 rows)
 }}}

 However, using `_ST_DistanceUnCached` in the latter statement recovers the
 expected result:
 {{{
 sample=# SELECT N.node_id, P.iid,
 _ST_DistanceUnCached(P.outline::geography, N.location::geography)
 FROM N, P WHERE (N.node_id IN (1,2,3) AND P.iid=1);
  node_id | iid | _st_distanceuncached
 ---------+-----+----------------------
        1 |   1 |     1951140.06556506
        2 |   1 |     1730626.41376862
        3 |   1 |     1727662.98350914
 (3 rows)
 }}}

 Statements above were tested on:
 {{{
 PostgreSQL 9.5.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5
 20150623
 (Red Hat 4.8.5-4), 64-bit

 POSTGIS="2.2.1 r14555" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6
 March 2012"
 GDAL="GDAL 1.11.2, released 2015/02/10" LIBXML="2.9.1"
 LIBJSON="0.11" RASTER
 }}}

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