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

标签 python gis openstreetmap osmnx

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/

相关文章:

c# - 如何在 .net 核心中使用 Openstreetmap(osm) 离线图 block 文件?

python - 当 OpenCV 检测到正图像时,处理时间非常长

python - 如何根据 python (Django) 中的日期时间范围过滤对象

Python 正则表达式\数字添加\0x

python - python 模式装饰器中奇怪的类行为

delphi - 在哪里可以找到 Delphi 的 map 控件?

gis - 将属性添加到 qgis 中重叠多边形的数据点

gis - 使用 PGRouting 基于 GTFS 的交通规划

flutter - 如何在 Flutter 上使用 OpenStreetMaps

仅带国家边界的传单 map