Networkx如何在多有向图中求特定边的长度

2024-10-04 03:21:09 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我从法国的一个地方下载了drive_服务的图表,我正在尝试获取特定边缘的长度。。有什么办法吗?

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}})


Tags: nameimportas地方图表placedrive边缘
1条回答
网友
1楼 · 发布于 2024-10-04 03:21:09

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

因此,如果要获取两个节点之间的所有长度,则需要迭代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))

相关问题 更多 >