这是CSV格式的PostgreSQL示例。
row,latitude,longitude 1,42.082513,-72.621498 2,42.058588,-72.633386 3,42.061118,-72.631541 4,42.06035,-72.634145
我在世界各地有成千上万行这样的跨越坐标。
我只想查询表中特定半径内的坐标。如何使用PostGIS和PostgreSQL做到这一点?
我结合了欧文(Erwin)和帕特里克(Patrick)的答案。
-- Add geography column ALTER TABLE googleplaces ADD COLUMN gps geography; UPDATE googleplaces SET gps = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326); CREATE INDEX googleplaces_gps ON googleplaces USING gist(gps); SELECT * FROM my_table WHERE ST_DWithin(gps, ST_SetSRID(ST_MakePoint(-72.657, 42.0657), 4326), 5 * 1609);