平铺 OSM - 找到给定 city/state 的边界

Tiled OSM's - find the bounds of given city/state

我使用立交桥 api 下载了几张美国地图,现在我在本地有美国地图,我想获取给定城市(或州)的边界而不用涉及 API.

我应该搜索某些标签或关系吗?我假设我必须从标记为 (k=namev=city_name) 和 (k=placev=city) 的节点开始,并基于它的 id 到找到一个 way 节点。

我的假设正确吗?如果是的话,你能给我一些指导吗,一旦我有了城市对应的节点,我应该找什么?

注意。我浏览了 OSM wiki 并研究了一点 OSM XML 格式,但是到目前为止我无法全面了解 OSM XML 结构,所以也许有更多经验的人这对我有帮助。

行政边界映射为ways or relations with a boundary=administrative tag. The boundary type is specified by an admin_level. The admin_level value for cities differs from country to country and can even include multiple values. But for most countries, admin_level values for cities range from 6 to 8 (for the US it starts even from 5). In contrast, US states have an admin_level of 4. With the help of these keys you can construct a Overpass query for specific cities/stares, or even query for all cities and states. Here is an example for Denver:

[out:json][timeout:25];
// gather results
(
  way["boundary"="administrative"]["admin_level"~"6|7|8"]["name"="Denver"];
  relation["boundary"="administrative"]["admin_level"~"6|7|8"]["name"="Denver"];
);
// print results
out body;
>;
out skel qt;

您可以看到它会产生多个结果。查看 place 和 admin_level 标签以确定结果的重要性。

或者,当使用 nominatim.openstreetmap.org 处的实例时,您可以使用地理编码器,例如 Nominatim. Here is an example for Denver. In contrast to Overpass API, Nominatim will weight the results by importance. It also supports multiple output formats and can return polygons (which you can use for determining the bounds). Please read about Nominatim's usage policy

另见 search engine results