OSMnx route_to_gdf function

17 Views Asked by At

I just have a question on the usage of the 'weight' argument in the route_to_gdf function. In https://osmnx.readthedocs.io/en/stable/user-reference.html, it says "weight (string) – if there are parallel edges between two nodes, choose lowest weight."

Based on this, I have some questions on OSMnx examples on https://github.com/gboeing/osmnx-examples/blob/main/notebooks/02-routing-speed-time.ipynb:

# calculate two routes by minimizing travel distance vs travel time
orig = list(G)[1]
dest = list(G)[120]
route1 = ox.shortest_path(G, orig, dest, weight="length")
route2 = ox.shortest_path(G, orig, dest, weight="travel_time")

# compare the two routes
route1_length = int(sum(ox.utils_graph.route_to_gdf(G, route1, "length")["length"]))
route2_length = int(sum(ox.utils_graph.route_to_gdf(G, route2, "length")["length"]))
route1_time = int(sum(ox.utils_graph.route_to_gdf(G, route1, "travel_time")["travel_time"]))
route2_time = int(sum(ox.utils_graph.route_to_gdf(G, route2, "travel_time")["travel_time"]))
print("Route 1 is", route1_length, "meters and takes", route1_time, "seconds.")
print("Route 2 is", route2_length, "meters and takes", route2_time, "seconds.")

I think the codes should be the following instead:

#Since route 2 is minimizing travel time, one should pick the edge that minimizes travel time if there are parallel edges, and then use the routes to compute minimum distance.
route2_length = int(sum(ox.utils_graph.route_to_gdf(G, route2, "travel_time")["length"]))

#Since route 1 is minimizing distance, one should pick the edge that minimizes length if there are parallel edges, and then use the routes to compute minimum travel time.
route1_time = int(sum(ox.utils_graph.route_to_gdf(G, route1, "length")["travel_time"]))

I apologize if I am wrong, but I look forward to hearing what you think. Thank you.

0

There are 0 best solutions below