>OSMnx 中的层级节点
>Hieararchy nodes in OSMnx
我正在与 OSMnx 和 Networkx 合作解决车辆路径问题。在我试图实现的解决方案中,我需要一些具有较低层次结构的节点直接与具有较高层次结构的节点连接,但是,如果 OSMnx 可以选择这样做,这会更容易。有人知道 OSMnx 是否可行吗?
谢谢
编辑
使用 OSMnx,我以这种方式加载具有不同层次结构的图形和道路节点:
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 给出了道路的层次结构。假设我有一个位置并像这样计算离该位置最近的节点:
orig_node = ox.get_nearest_node(G, c_ori,method='haversine') #c_ori = position
原来 orig_node 位于等级较低的道路上(住宅和未分类)。我需要知道 OSMnx 是否有办法将该节点直接连接到最近的具有更高层次结构的节点(主干、主节点等)?
谢谢
OSMnx 没有内置的功能,只能搜索特定层次结构级别的道路。但是你可以通过简单地制作第二个图表来只搜索你想要的道路类型来做到这一点:
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
我正在与 OSMnx 和 Networkx 合作解决车辆路径问题。在我试图实现的解决方案中,我需要一些具有较低层次结构的节点直接与具有较高层次结构的节点连接,但是,如果 OSMnx 可以选择这样做,这会更容易。有人知道 OSMnx 是否可行吗?
谢谢
编辑
使用 OSMnx,我以这种方式加载具有不同层次结构的图形和道路节点:
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 给出了道路的层次结构。假设我有一个位置并像这样计算离该位置最近的节点:
orig_node = ox.get_nearest_node(G, c_ori,method='haversine') #c_ori = position
原来 orig_node 位于等级较低的道路上(住宅和未分类)。我需要知道 OSMnx 是否有办法将该节点直接连接到最近的具有更高层次结构的节点(主干、主节点等)?
谢谢
OSMnx 没有内置的功能,只能搜索特定层次结构级别的道路。但是你可以通过简单地制作第二个图表来只搜索你想要的道路类型来做到这一点:
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