osmnx 是一种 Python 工具,可让您从 OpenStreetMap 下载 map 并将其用作 Networkx 图表。例如,我可以使用以下命令获取 LA 的街道 map :
osmnx.graph_from_place('Los Angeles, CA, USA', network_type='drive')
现在我正在尝试下载伊朗德黑兰的一个地区。使用“德黑兰,伊朗”这个名称没有多大帮助,结果是错误的。但是,城市边界的 OSM ID 为 8775292,如以下链接所示:
https://www.openstreetmap.org/relation/8775292
那么,有没有办法给 OSMNx 边界 ID 而不是给它名称来查询?
谢谢!
最佳答案
根据 OSMnx documentation您可以将地点查询作为字符串或字典提供。查看usage examples每个的演示。使用字典似乎可以很好地返回您正在寻找的城市边界:
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()
is there a way to give OSMNx the boundary ID instead of giving it the name for query
不,OSMnx 通过查询 Nominatim 地理编码器检索边界多边形。
关于python osmnx - 如何根据边界ID从OpenStreetMap下载市区 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65064351/