[postgis-users] ST_DWithin, ST_Distance and <->
Regina Obe
lr at pcorp.us
Mon Nov 12 20:23:17 PST 2018
ST_Distance existed before we had <->.
If you are using PostgreSQL 9.5+ with PostGIS 2.2, you can just stick with using <->, but note that it doesn't always use and index. <-> only uses and index when it is in the ORDER BY clause and one side is a constant geometry (which you can achieve even when you don't have a constant by using a LATERAL clause).
In the case of geography though <-> will always give the sphere distance, while ST_Distance by default gives the spheroid distance. So ST_Distance is slightly more accurate to use for geography.
We accept patches on documentation BTW.
From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of Eric St-Georges
Sent: Monday, November 12, 2018 4:47 PM
To: postgis-users at lists.osgeo.org
Subject: [postgis-users] ST_DWithin, ST_Distance and <->
Hi,
Looking for official documentation or guidance regarding the usage of ST_DWithin, ST_Distance and <->, especially when it comes to using indices. For example, the ST_Distance page <https://postgis.net/docs/ST_Distance.html> itself doesn't mention that the function will not use indices.
For example:
If I want to get the closest point to another, why can't ST_Distance use an index, but <-> can?
Is there anyway to get a distance in meters or some other unit from the <-> operator on geography types?
if ST_DWithin and <-> and other similar functions/operators should be used when dealing with distance, what's the use case for ST_Distance?
Regards,
Eric St-Georges
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20181112/114d6706/attachment.html>
More information about the postgis-users
mailing list