[英]How to use ST_DWithin to find near point?
This is the first time I create a GIS query. 这是我第一次创建GIS查询。 In one table of my database, there is a column with point type. 在我的数据库的一个表中,有一个点类型的列。 Each record is one ATM machine. 每条记录都是一台ATM机。 I want to write a query to get ATM machines that near by my location within 1km range.How to use ST_DWithin in SQL query to find record? 我想编写一个查询来获取我的位置在1km范围内附近的ATM机。如何在SQL查询中使用ST_DWithin来查找记录?
SELECT *
FROM atm_finder
WHERE ST_Distance(ST_Transform(ST_GeomFromText('POINT([Lon] [Lat])',4326),26986),ST_Transform(location,26986)) <= 1000
Where [Lon] & [Lat] - GPS coordinates of the point. 其中[Lon]和[Lat] - 点的GPS坐标。 But so far as you used POINT type at first use: 但是,首先使用POINT类型:
SELECT AddGeometryColumn('atm_finder', 'location', 4326, 'POINT', 2);
Of course before that you should rename the field 'location' (in order to not lose the data) and fill the new one with this data. 当然,在此之前,您应该重命名字段“location”(以便不丢失数据)并使用此数据填充新字段。
I don't see well how ST_DWithin could be used with two points... 我不太清楚ST_DWithin如何用两点......
Something like that . 这样的事情。
select atm.id
from atm_finder atm
where ST_Distance(<your location>, atm.location) <= 1000
//1000 = meters, works fine with geography types
//have to check your projection with geometry types
The way your table is created looks strange to me, by the way... 顺便说一下,创建表格的方式对我来说很奇怪......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.