问题描述
我使用工具osm2pgsql -s modus将城市慕尼黑的地图(从openstreetMap)加载到了postgis中
I loaded the map of city Munich (from openstreetMap) into postgis with tool osm2pgsql -s modus
现在我怎么能以最有效的方式在100米以内的某个点(例如(a,b))附近找到所有商店
now how could I get all shops around a certain point, say (a,b), within 100 meters, in a most efficient way
我知道这就像
select name, shop
from planet_osm_point
where ST_DWithin(? ,ST_Point(a,b):geometry, 100)
非常感谢
推荐答案
查询已经是查询所需数据的正确有效的方法.
You query is already a correct and efficient way to query the data you need.
您只需要进行一次调整:函数St_Point
返回一个没有SRID的几何(顺便说一句,不需要强制转换为几何),但是必须设置SRID以避免错误:
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:
使用postgis函数St_SetSrid
设置srid:
Use the postgis function St_SetSrid
to set the srid:
ST_SetSrid(ST_Point(a, b), srid)
另请参见 St_SetSrid
如果使用默认选项运行osm2pgsql,则Srid应该为900913:
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);
有关纬向和空间参考的更多信息,请参见 https://en.wikipedia.org/wiki/SRID 和 http://spatialreference.org
For more infos about srid and spatial references see https://en.wikipedia.org/wiki/SRID and http://spatialreference.org
关于SRID 900913: https://en.wikipedia.org/wiki/Web_Mercator
About SRID 900913: https://en.wikipedia.org/wiki/Web_Mercator
这篇关于如何使用osm-postgis查询特定经度/纬度附近的所有商店?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!