osmnx - 过滤关系
问题描述
我正在尝试检索挪威主要道路的网络。但是,“int_ref”和“ref”标签不一致,导致道路出现间隙。查看 OpenStreetMap 中的道路时,我可以看到“部分”下的“关系”标签正是我所需要的。有没有办法使用 OSMnx 来检索它?有没有其他方法可以检索完整的道路?在基于 int_ref 过滤一条特定道路时,我使用以下代码行:
G1 = ox.graph_from_place(query = "Norway", retain_all = True, custom_filter = '["int_ref"~"E 39"]')
解决方案
不,OSMnx 过滤way
标签,而不是关系。如果您只想获得一个国家的主要道路,请参阅此答案:https ://stackoverflow.com/a/52412274/7321942
这样的事情可能会做你正在寻找的东西:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
# get the geometry of the norwegian mainland
gdf = ox.geocode_to_gdf('Norway')
geom = max(gdf['geometry'].iloc[0], key=lambda x: x.area)
# get all motorway/trunk roads
cf = '["highway"~"motorway|motorway_link|trunk|trunk_link"]'
G = ox.graph_from_polygon(geom, network_type='drive', custom_filter=cf)
# plot it
fig, ax = ox.plot_graph(G)
下载挪威大陆的所有区域大约需要 370 个 Overpass API 请求,因此发出所有这些请求需要一段时间。您可以在控制台的日志中查看其进度。
推荐阅读
- scala - 如何根据行数重新分区 Spark 数据帧?
- php - 回声
- ios - 如何在应用启动时获取活动通知列表
- java - 如何从不同的类中增加实例变量?
- visual-studio-code - 是否可以为键盘序列设置键盘快捷键?
- powerbi - 获取矩阵中每个月的上个月预测
- javascript - 如何在 react-intl 中使用数组字符串?
- testing - 如何使N个样本分布在jmeter中N> = M的M个线程上
- azure - Azure DevOps - 自定义任务 - 带有 Azure 身份验证的 PowerShell
- javascript - 使用 cPanel 中的新节点应用程序功能将文件同步到 S3