OSMNx - 我是否有可能从一个节点获得最短路径但没有连接到它的边?

OSMNx - Is it possible that I get shortest path from a node but no edge is connected to it?

我正在进行模拟,我想记录步行路径中步数的距离。

图表:

G = ox.graph_from_bbox(35.00843, 34.99174, 135.78775, 135.77495, network_type='walk')

所需的路径是:

ox.shortest_path(G, 305371702, 305371770)

我使用以下方法获取边缘数据:

edges = ox.graph_to_gdfs(G, nodes=False, edges=True)
edges=edges[['u','v','length']]

但是在我到达节点 5327529704 的最短路径的某个步骤中,事情变得很奇怪。当我在 G.nodes() 中获得此节点的 True 时,此节点的 'edges' 数据帧为空:

edges[edges['u']== 5327529704]

当然,我收到以下错误:

edges[edges['u']== 5327529704].loc[edges['v']== 5327529686].length.iloc[0]

最短路径中两个节点之间怎么可能没有边呢?我做错了什么?

所以我明白了,我试过使用:

G = ox.utils_graph.get_undirected(G)

但这并没有解决它。图我只需要检查两次,一次是起始节点在 u 上,一次是在 v.

这不是我希望做的,但现在我可以操纵数据以更好地满足我的目的。

这对我来说似乎一切正常...这是一个最小的可重现代码片段:

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

# make the graph and get shortest path
G = ox.graph_from_bbox(35.00843, 34.99174, 135.78775, 135.77495, network_type='walk')
path = ox.shortest_path(G, 305371702, 305371770)
print(path)

# look up the length of a specific edge
edges = ox.graph_to_gdfs(G, nodes=False, edges=True)
edges=edges[['u','v','length']]
print(edges[edges['u']== 5327529704].loc[edges['v']== 5327529686].length.iloc[0])

# see that edge's attribute data in the graph itself
print(G.edges[(5327529704, 5327529686, 0)])

# get the lengths of each edge in the path
edge_lengths = ox.utils_graph.get_route_edge_attributes(G, path, 'length')
print(edge_lengths)