Dear people of stackoverflow,
I made a routeplanner based on length and elevation. With both costfactors I get only results with an undirected graph. So the code is good for an undirect graph but doesn't work with a MultiDiGraph as input, which I want because it is necessary with elevation.
The errors I get:
number 1:
~\anaconda3\envs\environmentwithhighestversion\lib\site-
packages\osmnx\plot.py in
plot_graph_route(G, route, route_color, route_linewidth, route_alpha,
orig_dest_size, ax,
**pg_kwargs)
292
293 # scatterplot origin and destination points (first/last nodes in
route)
--> 294 x = (G.nodes[route[0]]["x"], G.nodes[route[-1]]["x"])
295 y = (G.nodes[route[0]]["y"], G.nodes[route[-1]]["y"])
296 ax.scatter(x, y, s=orig_dest_size, c=route_color,
alpha=route_alpha, edgecolor="none")
TypeError: 'NoneType' object is not subscriptable
Number 2:
~\anaconda3\envs\environmentwithhighestversion\lib\site-
packages\osmnx\utils_graph.py in get_route_edge_attributes(G, route,
attribute, minimize_key, retrieve_default)
263 """
264 attribute_values = []
--> 265 for u, v in zip(route[:-1], route[1:]):
266 # if there are parallel edges between two nodes, select the
one with the
267 # lowest value of minimize_key
TypeError: 'NoneType' object is not subscriptable
The code is partly altered, the original code is of G. Boeing (2021): https://github.com/gboeing/osmnx-examples/blob/main/notebooks/12-node-elevations-edge-grades.ipynb Here is also a reproducible example possible.
The code for the first error:
TypeError Traceback (most recent call
last)
<ipython-input-3-86e03594e5bd> in <module>
7 route_by_impedance = ox.shortest_path(G7, source, target,
weight="impedance")
8 print('Route Impedance:')
----> 9 fig, ax = ox.plot_graph_route(G7, route_by_impedance,
node_size=3)
10 def print_route_stats(route):
11 route_grades = ox.utils_graph.get_route_edge_attributes(G7,
route, "grade_abs")
The code for the second error:
ipython-input-4-4eb87f73e021> in print_route_stats(route)
9 #fig, ax = ox.plot_graph_route(G7, route_by_impedance, node_size=3)
10 def print_route_stats(route):
---> 11 route_grades = ox.utils_graph.get_route_edge_attributes(G7,
route, "grade_abs")
12 msg = "The average grade is {:.1f}% and the max is {:.1f}%"
13 print(msg.format(np.mean(route_grades) * 100,
np.max(route_grades) * 100))
Does anybody know why I get this problem?
Kind regards,
Damiaan