PostGIS中用于邻近搜索的ST_DWithin和ST_Distance有什么区别?


14

我有存储在表中的记录,而纬度/经度坐标存储在几何字段中。我想查找用户提供的参考点附近的所有记录。注意“附近”可能意味着小于100公里(可能更小)。

我看到的大多数示例都可以使用ST_DWithin。您有不能使用的理由ST_Distance吗?使用ST_DWithinST_Distance这样做有什么区别?

例如:

SELECT name, ST_AsText(coords)
FROM places
WHERE ST_DWithin(coords, ST_GeomFromText('POINT(-12.5842 24.4944)',4326), 1)

SELECT name, ST_AsText(coords)
FROM places
WHERE ST_Distance(coords, ST_GeomFromText('POINT(-12.5842 24.4944)',4326)) < 1

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.