How to query all shops around a certain longitude/latitude using osm-postgis?

删除回忆录丶 提交于 2019-12-12 00:16:51

问题


I loaded the map of city Munich (from openstreetMap) into postgis with tool osm2pgsql -s modus

now how could I get all shops around a certain point, say (a,b), within 100 meters, in a most efficient way

I know it is something like

select name, shop
from planet_osm_point
where ST_DWithin(? ,ST_Point(a,b):geometry, 100)

thanks a lot


回答1:


You query is already a correct and efficient way to query the data you need.

You only need one adjustments: The function St_Point returns a geometry without SRID (by the way, no cast to geometry is needed), but the SRID must be set, to avoid the error:

ERROR: Operation on two GEOMETRIES with different SRIDs

Use the postgis function St_SetSrid to set the srid:

ST_SetSrid(ST_Point(a, b), srid)

See also St_SetSrid

If you ran osm2pgsql using the default options, the srid should be 900913:

SELECT name, shop
FROM planet_osm_point
WHERE ST_DWithin(way ,ST_SetSrid(ST_Point(a, b), 900913), 100);

For more infos about srid and spatial references see https://en.wikipedia.org/wiki/SRID and http://spatialreference.org

About SRID 900913: https://en.wikipedia.org/wiki/Web_Mercator



来源:https://stackoverflow.com/questions/31968656/how-to-query-all-shops-around-a-certain-longitude-latitude-using-osm-postgis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!