[postgis-tickets] [PostGIS] #4223: ST_Distance returns 0 instead of 5

PostGIS trac at osgeo.org
Thu Nov 1 01:15:51 PDT 2018


#4223: ST_Distance returns 0 instead of 5
---------------------+---------------------------
 Reporter:  br0ke    |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  medium   |  Milestone:  PostGIS 2.5.1
Component:  postgis  |    Version:  2.5.x
 Keywords:           |
---------------------+---------------------------
 Hey!

 ST_Distance function returns incorrect value but _ST_DistanceUncached
 returns correct. And it's not a rare, weird case: I have two simple
 rectangles, distance between is 5 meters.

 [[Image(https://image.ibb.co/cryRL0/Screenshot-
 from-2018-11-01-13-10-10.png)]]

 My query (also can be found here [https://pastebin.com/QTfV19vh]):
 {{{
 SELECT
         ST_Distance(f1.geog, f2.geog),
         _ST_DistanceTree(f1.geog, f2.geog),
         _ST_DistanceUncached(f1.geog, f2.geog)
 FROM
         LATERAL (
                 SELECT ST_Transform(
                         ST_SetSRID(
                                 ST_GeomFromGeoJson('{"type": "Polygon",
 "coordinates": [[[-5, 0], [-5, 100], [5, 100], [5, 0], [-5, 0]]]}'),
                                 32641
                         ),
                         4326
                 )::geography AS geog
         ) AS f1,
         LATERAL (
                 SELECT ST_Transform(
                         ST_SetSRID(
                                 ST_GeomFromGeoJson('{"type": "Polygon",
 "coordinates": [[[-10, 30], [-10, 40], [-20, 40], [-20, 30], [-10,
 30]]]}'),
                                 32641
                         ),
                         4326
                 )::geography AS geog
         ) AS f2,
         generate_series(1, 10);
 }}}

 Output:
 {{{
  st_distance | _st_distancetree | _st_distanceuncached
 -------------+------------------+----------------------
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
            0 |                0 |     4.98653949096524
 }}}

 My PostGIS version:
 {{{
 POSTGIS="2.5.0 r16836" [EXTENSION] PGSQL="100" GEOS="3.5.1-CAPI-1.9.1
 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.1.2, released
 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" TOPOLOGY
 RASTER
 }}}

 My PostgreSQL version:
 {{{
 PostgreSQL 10.5 (Debian 10.5-2.pgdg90+1) on x86_64-pc-linux-gnu, compiled
 by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
 }}}

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