【发布时间】:2021-10-03 19:06:58
【问题描述】:
我需要为道路网络上的一些节点制作一个 GeoDataFrame(使用 OSMnx 从 OpenStreetMap 中提取)。在下面的代码中,graph_proj 是我正在使用其节点的图,点是 start_point 和 end_point:
import osmnx as ox
import geopandas as gpd
nodes_proj, edges_proj = ox.graph_to_gdfs(graph_proj, nodes=True, edges=True)
# Finding the nodes on the graph nearest to the points
start_node = ox.nearest_nodes(graph_proj, start_point.geometry.x, start_point.geometry.y, return_dist=False)
end_node = ox.nearest_nodes(graph_proj, end_point.geometry.x, end_point.geometry.y, return_dist=False)
start_closest = nodes_proj.loc[start_node]
end_closest = nodes_proj.loc[end_node]
# Create a GeoDataBase from the start and end nodes
od_nodes = gpd.GeoDataFrame([start_closest, end_closest], geometry='geometry', crs=nodes_proj.crs)
在最后一步(“# Create a GeoDataBase...”等)中,抛出了一个错误。显然,它与传递给 GeoDataFrame 函数的 3 维数组有关。我传递位置([start_closest, end_closest])的方式会导致 3D 数组,这对吗? (错误消息显示,'必须通过二维输入。shape=(2, 1, 7)')我尝试转置此数组,但 GeoPandas 无法找到“几何”列。如何以一种可以接受的方式传递这个论点?
【问题讨论】:
标签: python arrays dataframe geopandas osmnx