简体   繁体   English

OSMNX Shortest path Nodes - 获取节点经过的时间

[英]OSMNX Shortest path Nodes - Get node traveled time

I wanted to get the travel time between nodes in shortest path route using Osmnx.我想使用 Osmnx 获得最短路径路径中节点之间的旅行时间。 Is there a way to get the travel time between the nodes.有没有办法获得节点之间的旅行时间。

import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)
import pandas as pd

pla__version__Piedmont, CA, USA
G = ox.graph_from_place(place, network_type='drive')

orig = list(G)[0]
dest = list(G)[-1]
route = nx.shortest_path(G, orig, dest)
#fig, ax = ox.plot_graph_route(G, route, route_linewidth=6, node_size=0, bgcolor='k')


for i, val in enumerate(route):
    print(i, val, G.nodes[val]['x'], G.nodes[val]['y'])

I want to store the nodes, the latitude and longitude which is implemented in the above loop, but is there a way to store also the travel time between the two nodes and/or distance between the two nodes.我想存储在上述循环中实现的节点、纬度和经度,但是有没有办法存储两个节点之间的旅行时间和/或两个节点之间的距离。

OSM's data on speeds and travel times tend to be spotty. OSM 关于速度和旅行时间的数据往往参差不齐。 Use OSMnx's speed module to impute missing edge speeds and calculate free-flow travel times.使用 OSMnx 的速度模块来估算缺失的边缘速度并计算自由流动的行程时间。

import networkx as nx
import osmnx as ox
import pandas as pd
ox.config(use_cache=True, log_console=True)

place = 'Piedmont, CA, USA'
G = ox.graph_from_place(place, network_type='drive')

# impute missing edge speeds and add travel times
G = ox.add_edge_speeds(G)
G = ox.add_edge_travel_times(G)

# calculate route minimizing some weight
orig, dest = list(G)[0], list(G)[-1]
route = nx.shortest_path(G, orig, dest, weight='travel_time')

# OPTION 1: see the travel time for the whole route
travel_time = nx.shortest_path_length(G, orig, dest, weight='travel_time')
print(round(travel_time))

# OPTION 2: loop through the edges in your route
# and print the length and travel time of each edge
for u, v in zip(route[:-1], route[1:]):
    length = round(G.edges[(u, v, 0)]['length'])
    travel_time = round(G.edges[(u, v, 0)]['travel_time'])
    print(u, v, length, travel_time, sep='\t')

# OPTION 3: use get_route_edge_attributes
cols = ['osmid', 'length', 'travel_time']
attrs = ox.utils_graph.get_route_edge_attributes(G, route)
print(pd.DataFrame(attrs)[cols])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSMNX 最短路径 - 如果无法访问,如何跳过节点并采用下一个最近的节点 - OSMNX Shortest Path - How to skip node if not reachable and take the next nearest OSMnx:一组起点和终点的最短路径 - OSMnx: Shortest path for a set of origins and destinations 优化 osmnx 网络中的最短路径计算 - Optimize shortest path calculation in an osmnx network 计算从设置节点到所有其他节点的最短路径,其中某些节点被禁止从路径 - Calculating shortest path from set node to all other nodes, with some nodes forbidden from path 转换为 LineString 时的最短路径错过了 OSMNX 中的路径 - Shortest route when converted to LineString misses the path in OSMNX osmnx 如何知道最短路径中 plot 的哪些边 - How does osmnx know which edges to plot in shortest path OSMnx:有没有办法找到两个坐标之间的准确最短路径? - OSMnx: Is there a way to find an accurate shortest path between 2 coordinates? OSMNx : 使用 OSM id 获取节点坐标 - OSMNx : get coordinates of nodes using OSM id 到选定节点的总体最短路径 - Overall shortest path to selected nodes 为什么新的 osmnx 'nearest_nodes' function 返回的结果与旧的 function 'get_nearest_node' 不同? - Why does new osmnx 'nearest_nodes' function return different results than old function 'get_nearest_node'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM