繁体   English   中英

python osmnx - 如何根据边界 ID 从 OpenStreetMap 下载市区 map?

[英]python osmnx - How to download a city district map from OpenStreetMap based on the boundary ID?

osmnx 是一个 Python 工具,可让您从 OpenStreetMap 下载地图并将其作为 Networkx 图形使用。 例如,我可以使用以下命令获取洛杉矶的街道 map:

osmnx.graph_from_place('Los Angeles, CA, USA', network_type='drive')

现在我正在尝试下载伊朗德黑兰内的一个地区。 使用“德黑兰,伊朗”这个名字并没有太大帮助,结果是错误的。 但是,城市边界的 OSM ID 为 8775292,可在以下链接中找到:

https://www.openstreetmap.org/relation/8775292

那么,有没有办法给 OSMNx 提供边界 ID 而不是给它命名以进行查询?

谢谢!

根据 OSMnx文档,您可以将位置查询提供为字符串或字典。 请参阅每个示例的使用示例 使用 dict 似乎可以很好地返回您正在寻找的城市边界:

import osmnx as ox
ox.config(use_cache=True, log_console=True)

# define the place query
query = {'city': 'Tehran'}

# get the boundaries of the place
gdf = ox.geocode_to_gdf(query)
gdf.plot()

# or just get the street network within the place
G = ox.graph_from_place(query, network_type='drive')
fig, ax = ox.plot_graph(G, edge_linewidth=0)

如果您用波斯语或英语查询更具体的字符串,它也可以正常工作:

# query in persian
gdf = ox.geocode_to_gdf('شهر تهران')
gdf.plot()

# or in english
gdf = ox.geocode_to_gdf('Tehran City')
gdf.plot()

有没有办法给 OSMNx 提供边界 ID 而不是给它命名以进行查询

不,OSMnx 通过查询 Nominatim 地理编码器来检索边界多边形。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM