当我使用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'
答案 0 :(得分:1)
确保您使用的是最新发布的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)
答案 1 :(得分:0)
将networkx导入为nx
nx.Graph.add_edge(行[' u'],行[' v']) 作品!
显然你和v不能作为选项!新的networkx版本是否有所改变?