【问题标题】:Networkx How to get length of a specific edge in multidigraphNetworkx如何在多向图中获取特定边的长度
【发布时间】:2019-07-27 13:47:06
【问题描述】:

嗨,我从法国的一个地方下载了 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': '住宅', '几何': , 'osmid':31297114,'junction':'roundabout','oneway':真,'length': 26.204}})

【问题讨论】:

  • graph_aubervillier[348206084][256242027]['length'](其他人可能会对此回复提供更多背景信息)。
  • @Joel 不完全——我认为图形对象是一个 MultiDiGraph,所以你可能需要graph_aubervillier[348206084][256242027][0]['length']。但是如果两个节点之间有多个边,最好迭代它。

标签: python graph attributes networkx osmnx


【解决方案1】:

当您调用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))

【讨论】:

  • 这正是我所需要的,谢谢! :-)
  • 如果这解决了你的问题,你应该投票并接受这个答案。 :)
  • 请安德鲁,我是初学者.. 对于同一张图,我尝试将其写为 shapefile 与 "nx.write_shp( graph_aubervillier , "pathfile/file1/file2 " ) " 但它返回一个错误.. :/ 这个 : TypeError: 'int' object is not subscriptable 你知道为什么吗?
  • 抱歉,我不确定。可能值得另一个问题 - 确保发布错误的完整堆栈跟踪。你看过write_shp - networkx.github.io/documentation/stable/reference/readwrite/…的文档吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-12
  • 1970-01-01
  • 1970-01-01
  • 2017-08-16
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
相关资源
最近更新 更多