Networkx如何获取多向图中特定边的长度

Networkx How to get length of a specific edge in multidigraph

你好,我从法国的某个地方下载了 drive_service 的图表,我正在尝试获取特定边的长度.. 有办法吗?

import osmnx as ox

name_place = 'Aubervilliers, France'

graph_aubervillier = ox.graph_from_address( name_place ,network_type="drive_service")


graph_aubervillier[348206084][256242027]

AtlasView({0: {'highway': 'residential', 'geometry': , 'osmid': 31297114, 'junction': 'roundabout', 'oneway': True, 'length': 26.204}})

当您调用 graph_aubervillier[348206084][256242027] 时,您将返回这两个节点之间所有可能的边。请注意,该图是一个MultiDiGraph,它可以在两个节点之间有多个边。

所以,如果你想获得两个节点之间的所有长度,你需要遍历 AtlasView 对象:

import osmnx as ox

name_place = 'Aubervilliers, France'

graph_aubervillier = ox.graph_from_address(name_place ,network_type="drive_service")

edges_of_interest = graph_aubervillier[348206084][256242027]

for edge in edges_of_interest.values():
    # May not have a length. Return None if this is the case.
    # Could save these to a new list, or do something else with them. Up to you.
    print(edge.get('length', None))