首页 > 解决方案 > 过滤关系

问题描述

我正在尝试检索挪威主要道路的网络。但是,“int_ref”和“ref”标签不一致,导致道路出现间隙。查看 OpenStreetMap 中的道路时,我可以看到“部分”下的“关系”标签正是我所需要的。有没有办法使用 OSMnx 来检索它?有没有其他方法可以检索完整的道路?在基于 int_ref 过滤一条特定道路时,我使用以下代码行:

G1 = ox.graph_from_place(query = "Norway", retain_all = True, custom_filter = '["int_ref"~"E 39"]')

道路标签和关系

标签: osmnx

解决方案


不,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 请求,因此发出所有这些请求需要一段时间。您可以在控制台的日志中查看其进度。


推荐阅读