[postgis-users] Unexpected ST_DWithin result when using geography
Regina Obe
lr at pcorp.us
Tue Feb 8 10:22:01 PST 2022
Yes I would consider this a bug as I would expect anything on the line should also be within the buffer.
I’m not sure if it’s something with the buffer logic piggy backing on geometry or the distance logic in geography itself.
I notice that
SELECT ST_DWithin(
'SRID=4326;LINESTRING(7.1670005 45.9968257,7.1670216
45.9969537,7.1670216 45.9971326, 7.1670484 45.9972789, 7.1671905
45.9974074, 7.1672844 45.9974801, 7.1659165 46.0005209, 7.1653103
46.0010221, 7.1652359 46.0013015)'::geography,
'SRID=4326;POINT(7.1672844 45.9974801)'::geography,0
);
Returns true, but your case of buffering, as you stated returns false and checking the distances
SELECT ST_Distance(
ST_Buffer('SRID=4326;LINESTRING(7.1670005 45.9968257,7.1670216 45.9969537,7.1670216 45.9971326, 7.1670484 45.9972789, 7.1671905 45.9974074, 7.1672844 45.9974801, 7.1659165 46.0005209, 7.1653103 46.0010221, 7.1652359 46.0013015)'::geography, 1.0),
'SRID=4326;POINT(7.1672844 45.9974801)'::geography);
Returns 0.99478251
I tested the usual suspects:
SELECT _ST_DistanceTree(
ST_Buffer('SRID=4326;LINESTRING(7.1670005 45.9968257,7.1670216 45.9969537,7.1670216 45.9971326, 7.1670484 45.9972789, 7.1671905 45.9974074, 7.1672844 45.9974801, 7.1659165 46.0005209, 7.1653103 46.0010221, 7.1652359 46.0013015)'::geography, 1.0),
'SRID=4326;POINT(7.1672844 45.9974801)'::geography);
SELECT _ST_DistanceUncached(
ST_Buffer('SRID=4326;LINESTRING(7.1670005 45.9968257,7.1670216 45.9969537,7.1670216 45.9971326, 7.1670484 45.9972789, 7.1671905 45.9974074, 7.1672844 45.9974801, 7.1659165 46.0005209, 7.1653103 46.0010221, 7.1652359 46.0013015)'::geography, 1.0),
'SRID=4326;POINT(7.1672844 45.9974801)'::geography);
And they all return 0.9947
From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of satoshi
Sent: Monday, February 7, 2022 2:28 AM
To: postgis-users at lists.osgeo.org
Subject: [postgis-users] Unexpected ST_DWithin result when using geography
Hello,
This query:
```
SELECT ST_DWithin(
ST_Buffer('SRID=4326;LINESTRING(7.1670005 45.9968257,7.1670216 45.9969537,7.1670216 45.9971326, 7.1670484 45.9972789, 7.1671905 45.9974074, 7.1672844 45.9974801, 7.1659165 46.0005209, 7.1653103 46.0010221, 7.1652359 46.0013015)'::geography, 1.0),
'SRID=4326;POINT(7.1672844 45.9974801)'::geography,
0.0
);
```
Returns `FALSE`. Note that the point that is passed as the second parameter to `ST_DWithin` is part of the `LINESTRING` passed in the first parameter, so I expect it to return `TRUE`.
When removing the first or last point from the `LINESTRING`, then it correctly returns `TRUE`.
When using `geometry` instead of `geography` and using 0.0000105 for the buffer (which is roughly 1 meter at that latitude), then it correctly returns `TRUE`.
Could somebody comment on this and let me know why this would happen (if not a bug)?
Thank you,
Dario
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20220208/5914a2d9/attachment.html>
More information about the postgis-users
mailing list