【问题标题】:Plot multiple routes using osmnx使用 osmnx 绘制多条路线
【发布时间】:2021-04-17 09:52:35
【问题描述】:

我正在尝试绘制多条路线,但弹出错误 - networkx.exception.NetworkXError:nbunch 序列中的节点 [20461931, 75901933] 不是有效节点。

绘制单个路线不再是问题,但绘制在一起时会引发错误。


import networkx as nx
import osmnx as ox


# Create Graph 
G = ox.graph_from_place('Munich, Germany', network_type='drive')


# route1 calc
origin_node = 20461931
destination_node =   75901933
route1 = nx.shortest_path(G, origin_node, destination_node)

# route2 calc
start =   (48.1336081,  11.58172095)
end = (48.17822992, 11.53754219)
start_node = ox.get_nearest_node(G, start)
end_node = ox.get_nearest_node(G, end)
route2 = nx.shortest_path(G, start_node, end_node, weight='travel_time')

#plot the route with folium
route_list = [route1,route2]
route_map = ox.plot_route_folium(G,route_list)

# save as html file then display map as an iframe
filepath = 'route.html'
route_map.save(filepath)
 

【问题讨论】:

    标签: folium osmnx


    【解决方案1】:

    您正在向它传递一个 列表列表 节点,而不是节点列表。使用详情请参阅docs

    import osmnx as ox
    ox.config(use_cache=True, log_console=True)
    
    G = ox.graph_from_place('Munich, Germany', network_type='drive')
    route1 = ox.shortest_path(G, 20461931, 75901933, weight=None)
    
    orig = ox.get_nearest_node(G, (48.1336081,  11.58172095))
    dest = ox.get_nearest_node(G, (48.17822992, 11.53754219))
    route2 = ox.shortest_path(G, orig, dest, weight='travel_time')
    
    route_map = ox.plot_route_folium(G, route1, route_color='#ff0000', opacity=0.5)
    route_map = ox.plot_route_folium(G, route2, route_map=route_map, route_color='#0000ff', opacity=0.5)
    route_map.save('route.html')
    

    【讨论】:

    猜你喜欢
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2020-03-05
    • 2017-06-13
    相关资源
    最近更新 更多