#4223 closed defect (fixed)
ST_Distance returns 0 instead of 5
Reported by: | br0ke | Owned by: | pramsey |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.5.1 |
Component: | postgis | Version: | 2.5.x -- EOL |
Keywords: | Cc: |
Description
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.
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
Change History (6)
comment:2 by , 6 years ago
WITH g AS ( SELECT 'POLYGON((58.5112113206308 0,58.5112113200772 0.000901937525203378,58.511300910044 0.000901937636668872,58.5113009105976 0,58.5112113206308 0))'::geography AS a, 'POLYGON((58.5111665256017 0.000270581240841207,58.5111665255629 0.000360774987788249,58.5110769356128 0.000360774943200728,58.5110769356515 0.000270581207400566,58.5111665256017 0.000270581240841207))'::geography AS b ) SELECT _ST_DistanceTree(a, b), _ST_DistanceUncached(a, b) FROM g;
Note:
See TracTickets
for help on using tickets.
Good ticket. Can reproduce and appreciate the terse example.