OSMNX KeyError: 'x' when trying to get_nearest_nodes()

OSMNX KeyError: 'x' when trying to get_nearest_nodes()

我目前有一个流程

  1. 使用 ox.geocode_to_gdf()
  2. 下载 Open Street 数据
  3. 获取 Geopackage 边和节点使用并使用 gpd.overlay() 根据另一个地图编辑边和节点
  4. 使用 ox.graph_from_gdfs()
  5. 将编辑的边转换回 OSMNX 作为图形

在这个阶段,我有一个图表(样本here) 我想用它来估计某些点之间的最短路径。我有这些点的东向和北向,我正在尝试使用

让他离这些坐标最近的节点
nodes_flood = ox.distance.get_nearest_nodes(g_post_200_Cur_centre, Easting, Northing)

这样我就可以 运行 nx.shortest_path() 使用图形和目标节点。但是我收到一条错误消息

File "<ipython-input-74-ed9774662a83>", line 1, in <module>
nodes_flood = ox.distance.get_nearest_nodes(g_post_200_Cur_centre, Easting, Northing)

File "/Users/opt/anaconda3/envs/Kinshasa/lib/python3.7/site-packages/osmnx/distance.py", line 256, in get_nearest_nodes
nn = [get_nearest_node(G, (y, x), method="haversine") for x, y in zip(X, Y)]

File "/Users/opt/anaconda3/envs/Kinshasa/lib/python3.7/site-packages/osmnx/distance.py", line 256, in <listcomp>
nn = [get_nearest_node(G, (y, x), method="haversine") for x, y in zip(X, Y)]

File "/Users/opt/anaconda3/envs/Kinshasa/lib/python3.7/site-packages/osmnx/distance.py", line 138, in get_nearest_node
df = pd.DataFrame(coords, columns=["node", "x", "y"]).set_index("node")

File "/Users/opt/anaconda3/envs/Kinshasa/lib/python3.7/site-packages/pandas/core/frame.py", line 563, in __init__
data = list(data)
File "/Users/opt/anaconda3/envs/Kinshasa/lib/python3.7/site-packages/osmnx/distance.py", line 137, in <genexpr>
coords = ((n, d["x"], d["y"]) for n, d in G.nodes(data=True))

KeyError: 'x'

不确定是什么原因造成的。我有 OSMNX v1.0.

我通过将方法参数传递给 get_nearest_nodes() 来修复错误。如果您选择 'kdtree' 作为方法,则不会出现错误。

nodes_flood = ox.distance.get_nearest_nodes(g_post_200_Cur_centre, Easting, Northing, method='kdtree')

但是,如果我没有传递方法名,我仍然不知道错误的原因。