2

当我使用python时会发生以下情况osmnx

graph = osmnx.graph_from_polygon(Data.bbox)

gdf_nodes, gdf_edges = osmnx.save_load.graph_to_gdfs(
        graph,
        nodes=True, edges=True,
        node_geometry=True,
        fill_edge_geometry=True)
print(gdf_edges['u']) # prints the values nicely

graph2 = osmnx.save_load.gdfs_to_graph(gdf_nodes, gdf_edges) # misses 'v' and 'u' column in gdf_nodes

然后我收到以下错误:

  File "C:\Users\jpelda\AppData\Local\Continuum\anaconda3\lib\site-packages\osmnx\save_load.py", line 513, in gdfs_to_graph
    G.add_edge(u=row['u'], v=row['v'], key=row['key'], **attrs)

TypeError: add_edge() missing 2 required positional arguments: 'u_for_edge' and 'v_for_edge'
4

2 回答 2

2

确保您使用的是最新发布的 OSMnx 版本(截至今天为 0.8.1)和 NetworkX(截至今天为 2.1)。您的代码片段工作正常。完整的工作示例:

import networkx as nx
import osmnx as ox
print(ox.__version__)
print(nx.__version__)
graph = ox.graph_from_place('Piedmont, California, USA', network_type='drive')
gdf_nodes, gdf_edges = ox.graph_to_gdfs(
        graph,
        nodes=True, edges=True,
        node_geometry=True,
        fill_edge_geometry=True)
graph2 = ox.gdfs_to_graph(gdf_nodes, gdf_edges)

0.13.0之后 (2020-05-25)

ox.gdfs_to_graph()已被替换为ox.graph_from_gdfs()

如果您的 OSMnx 版本在 0.13.0 之后,请使用以下代码:

graph2 = ox.graph_from_gdfs(gdf_nodes, gdf_edges)
于 2018-05-16T20:12:57.680 回答
0
import networkx as nx

nx.Graph.add_edge(row['u'], row['v'])

作品!

显然 u 和 v 不能作为可选项给出!新的networkx版本有变化吗?

于 2018-04-27T08:26:26.573 回答