OSMNX是否可以通过长度和旅行时间来优化路线?
我想计算路线优化距离和旅行时间。我可以仅优化一个属性。
这是我的代码:
origin = (-33.4667,-70.7208)
destiny = (-33.367204, -70.506080)
orig_node = ox.distance.nearest_nodes(graph, origin[1],origin[0])
target_node = ox.distance.nearest_nodes(graph, destiny[1],destiny[0])
route = ox.distance.shortest_path(graph, orig_node, target_node, weight='travel-time')
length = int(sum(ox.utils_graph.get_route_edge_attributes(graph, route, "length")))
time = int(sum(ox.utils_graph.get_route_edge_attributes(graph, route, "time")))
print('Distancia: ',length/1000,' km') # prints 9201.784
print('Tiempo: ',time/60,' min')
ox.folium.plot_route_folium(graph, route, route_map=None, popup_attribute=None, tiles='cartodbpositron', zoom=1, fit_bounds=True)
谢谢!
I want to calculate route optimizing both distance and travel-time. I can do it optimizing just one attribute.
Here is my code:
origin = (-33.4667,-70.7208)
destiny = (-33.367204, -70.506080)
orig_node = ox.distance.nearest_nodes(graph, origin[1],origin[0])
target_node = ox.distance.nearest_nodes(graph, destiny[1],destiny[0])
route = ox.distance.shortest_path(graph, orig_node, target_node, weight='travel-time')
length = int(sum(ox.utils_graph.get_route_edge_attributes(graph, route, "length")))
time = int(sum(ox.utils_graph.get_route_edge_attributes(graph, route, "time")))
print('Distancia: ',length/1000,' km') # prints 9201.784
print('Tiempo: ',time/60,' min')
ox.folium.plot_route_folium(graph, route, route_map=None, popup_attribute=None, tiles='cartodbpositron', zoom=1, fit_bounds=True)
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论