用于创建新的空 GeoDataFrame 的语法

Syntax for creating a new, empty GeoDataFrame

我有一个 GeoDataFrame(我们称它为 Destinations),它是使用 GeoPandas 从点 shapefile 制作的。对于 Destinations 中的每个特征(如果术语有误,请纠正我),我需要在图形上找到最近的节点并将该节点保存到另一个 GeoDataFrame(我们称之为 Destination_nodes,稍后将用于最短-路径分析)。据推测,这需要创建一个新的空白 Destination_nodes GeoDataFrame 并在我循环遍历 Destinations 时向其附加节点。但是创建一个新的空 GeoDataFrame 的语法是什么?

对于 GeoDataFrame,您需要说明哪一列是几何图形,即包含您所说的特征。因此,您可以在创建时简单地指定空数据框的列,而不指定任何数据:

>>> dest = geopandas.GeoDataFrame(columns=['id', 'distance', 'feature'], geometry='feature')
>>> dest
Empty GeoDataFrame
Columns: [id, distance, feature]
Index: []
>>> dest.geometry
GeoSeries([], Name: feature, dtype: geometry)