Reputation: 3
I'm trying to plot multiple routes but error is popping up - networkx.exception.NetworkXError: Node [20461931, 75901933] in sequence nbunch is not a valid node.
Plotting individual route is no more problem but error is raised when plotted together.
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)
Upvotes: 0
Views: 3474
Reputation: 6422
You are passing it a list of lists of nodes, rather than a list of nodes. See the docs for usage details.
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')
Upvotes: 1