Opened 3 years ago

Closed 2 years ago

#5096 closed defect (invalid)

ST_DWithin does not include a point within the radius

Reported by: lybin Owned by: pramsey
Priority: medium Milestone: PostGIS 2.5.8
Component: postgis Version: 2.5.x -- EOL
Keywords: Cc:

Description

POSTGIS="2.5.5" [EXTENSION] PGSQL="110" (procs need upgrade for use with "130") GEOS="3.8.0-CAPI-1.13.1 " PROJ="Rel. 6.3.1, February 10th, 2020" GDAL="GDAL 3.0.4, released 2020/01/28 GDAL_DATA not found" LIBXML="2.9.10" LIBJSON="0.13.1
" LIBPROTOBUF="1.3.3" RASTER
PostgreSQL 13.4 (Ubuntu 13.4-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit

I use image from https://registry.hub.docker.com/r/postgis/postgis/, I've tried 13-master and 14-master

DB dump attached to reproduce.

There are two points:

30.318, 53.917 - Mogilev, Belarus
20.94, 52.255 - Warsaw, Poland

Distance between points is around 620-660km, but does not exceed 1000km. I've check by formula and google maps.

# (Earth radius) * PI / 180 6370.986 * pi / 180 = 111.19468229846346

Converting km to degrees for select with ST_DWithin.

When I filter by 1000km / 111 = 8.993235821438365 ST_DWithin(location, 'SRID=4326;POINT(20.94 52.2)', 8.993235821438365) DB doesn't select point 30.318, 53.917 - Mogilev, Belarus ID:4

If I filter by 9.6 * 111.19468229846346 = 1067.4689500652491 km, result below:

soul=# select id, ST_DistanceSphere(location, 'SRID=4326;POINT(20.94 52.2)'), ST_Distance(location, 'SRID=4326;POINT(20.94 52.2)'), ST_Distance(location, 'SRID=4326;POINT(20.94 52.2)') * 111194.68229846346  from search_search where ST_DWithin(location, 'SRID=4326;POINT(20.94 52.2)', 9.6);
 id | st_distancesphere |     st_distance      |     ?column?      
----+-------------------+----------------------+-------------------
  4 |   654581.31171121 |     9.53388551431157 | 1060117.370833798
  3 |      6115.7293854 | 0.054999999999999716 | 6115.707526415459
(2 rows)

For point ID: 3, st_distancesphere - displays correct distance in meters, also st_distance and ?column? are correct too.

But for point ID:4 30.318, 53.917 - Mogilev, Belarus st_distance and ?column? are much bigger than st_distancesphere, so that why when I filter by 1000km this point not in result.

Where I mistake, or that is bug? Thank you.

Attachments (2)

soul_localhost-2022_02_11_23_27_00-dump.sql (3.7 KB ) - added by lybin 3 years ago.
image-20220214-100911.png (587.6 KB ) - added by lybin 3 years ago.

Download all attachments as: .zip

Change History (5)

by lybin, 3 years ago

Attachment: image-20220214-100911.png added

comment:1 by robe, 3 years ago

Milestone: PostGIS 2.5.6PostGIS 3.0.6

comment:2 by robe, 2 years ago

Milestone: PostGIS 3.0.6PostGIS 2.5.8

comment:3 by pramsey, 2 years ago

Resolution: invalid
Status: newclosed

This is user error, not a bug. ST_Distance against lonlats will return not-useful-in-real-world numbers. Your third column, a linear scaling of lonlats won't return correct answers outside of a very local area (and will have a directional bias built into it too). Use the geography type for exact answers on longlat inputs.

Note: See TracTickets for help on using tickets.