首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >> OSMnx中的分层节点

> OSMnx中的分层节点
EN

Stack Overflow用户
提问于 2020-04-30 01:21:43
回答 1查看 299关注 0票数 1

我正在与OSMnx和Networkx合作解决车辆路径问题。在我试图实现的解决方案中,我需要一些具有较低层次结构的节点与具有较高层次结构的节点直接连接,但是,如果OSMnx可以选择这样做,这将更容易。有人知道OSMnx是否能做到这一点吗?

谢谢

编辑

使用OSMnx,我以这种方式加载具有不同层次结构的图和道路节点:

代码语言:javascript
复制
G = ox.graph_from_place({'city':'Medellín', 'state':'Antioquia'},network_type='drive', buffer_dist=60000,
                                infrastructure='way["highway"]',
                                custom_filter='["highway"~"motorway|trunk|primary|secondary|tertiary|unclassified|residential"]')

custom_filter给了我道路的等级。假设我有一个位置,并计算离该位置最近的节点,如下所示:

代码语言:javascript
复制
orig_node = ox.get_nearest_node(G, c_ori,method='haversine') #c_ori = position

事实证明,orig_node在一条等级较低的道路上(住宅和非机密)。我需要知道OSMnx是否有一种方法直接将该节点与最近的具有更高层次结构的节点(主干、主节点等)连接起来?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-03 18:09:57

OSMnx没有内置的能力,只能搜索特定层次的道路。但是,您可以通过只搜索所需道路类型的第二个图表来完成这一任务:

代码语言:javascript
复制
import networkx as nx
import osmnx as ox
ox.config(log_console=True, use_cache=True)

# graph of all the streets you want to model
place = {'city': 'Medellín', 'state': 'Antioquia'}
cf = '["highway"~"motorway|motorway_link|trunk|trunk_link|primary|secondary|tertiary|unclassified|residential"]'
G = ox.graph_from_place(place, network_type='drive', buffer_dist=60000, custom_filter=cf)

# graph of only the streets you want to search
cf_search = '["highway"~"motorway|motorway_link|trunk|trunk_link"]'
G_search = ox.graph_from_place(place, network_type='drive', buffer_dist=60000, custom_filter=cf_search)

print(len(G)) #40341
print(len(G_search)) #4562

# find a node in the road types you want to search
point = -75.54838, 6.22752
orig = ox.get_nearest_node(G_search, point, method='haversine')
dest = list(G)[0]

# impute edge speeds, add travel times, solve shortest path
G = ox.add_edge_speeds(G)
G = ox.add_edge_travel_times(G)
route = nx.shortest_path(G, orig, dest, weight='travel_time')
len(route) #141
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61514371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档