python osmnx - 如何根据边界ID从OpenStreetMap下载市区地图?
python osmnx - How to download a city district map from OpenStreetMap based on the boundary ID?
osmnx 是一个 Python 工具,可让您从 OpenStreetMap 下载地图并将其用作 Networkx 图表。例如,我可以使用以下命令获取 LA 的街道地图:
osmnx.graph_from_place('Los Angeles, CA, USA', network_type='drive')
现在我正在尝试下载伊朗德黑兰的一个地区。使用名称 'Tehran, Iran' 没有多大帮助,结果是错误的。但是,城市边界的 OSM ID 为 8775292,如下 link 所示:
https://www.openstreetmap.org/relation/8775292
那么,有没有办法给 OSMNx 边界 ID 而不是给它名称来查询?
谢谢!
每个 OSMnx documentation you can provide your place query as either a string or a dict. See the 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 地理编码器检索边界多边形。
osmnx 是一个 Python 工具,可让您从 OpenStreetMap 下载地图并将其用作 Networkx 图表。例如,我可以使用以下命令获取 LA 的街道地图:
osmnx.graph_from_place('Los Angeles, CA, USA', network_type='drive')
现在我正在尝试下载伊朗德黑兰的一个地区。使用名称 'Tehran, Iran' 没有多大帮助,结果是错误的。但是,城市边界的 OSM ID 为 8775292,如下 link 所示:
https://www.openstreetmap.org/relation/8775292
那么,有没有办法给 OSMNx 边界 ID 而不是给它名称来查询?
谢谢!
每个 OSMnx documentation you can provide your place query as either a string or a dict. See the 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 地理编码器检索边界多边形。