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

10-04 16:43