好吧,我没有下载你的数据,但我的数据库中已经加载了几乎所有拉丁美洲的 openstreetmaps 数据,我相信它会这样做。
这是一个城市最近的州的一个例子:
select distinct on (a.name)
a.name as city,
b.name as state,
min(St_Distance(b.way, a.way)) as d
from planet_osm_point as a,
(SELECT name, way, place from planet_osm_point WHERE place='state') as b
where a.place='city' group by 1,2 order by 1 asc;
但这并不准确,假设您可以使用多边形表进行更好的猜测:
select a.name as city,b.name as state,b.place
from planet_osm_point as a, planet_osm_polygon as b
where St_Contains(b.way, a.way)
and a.place='city'; -- and b.place='state' -- my polys table aren't tagged properly so I ignored polys.place
希望它有效:)。