gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:32:52 25 4
gpt4 key购买 nike

你好,我从法国的某个地方下载了 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))

关于python - Networkx如何获取多向图中特定边的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55013886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com