Borillar0821
Borillar0821

Reputation: 83

Syntax for creating a new, empty GeoDataFrame

I have a GeoDataFrame (let's call it Destinations) that was made from a point shapefile using GeoPandas. For every feature (correct me if the terminology is wrong) in Destinations, I need to find the nearest node on a graph and save that node to another GeoDataFrame (let's call it Destination_nodes, it will be used later for shortest-path analysis). Presumably, this requires creating a new, blank Destination_nodes GeoDataFrame and appending nodes to it as I loop through Destinations. But what is the syntax for creating a new empty GeoDataFrame?

Upvotes: 8

Views: 10574

Answers (2)

Ksenia
Ksenia

Reputation: 13

Unfortunately, I can't comment on the @Cimbali's answer, but would like to complete it. To avoid UserWarning when appending or concatenating newly created empty GeoDataFrame, you need to add crs parameter, for example:

dest = geopandas.GeoDataFrame(columns=['id', 'distance', 'feature'], geometry='feature', crs='EPSG:4326')

Upvotes: 1

Cimbali
Cimbali

Reputation: 11405

For a GeoDataFrame you need to say which column will be the geometry, i.e. contain features as you say. So you could simply specify the columns of your empty dataframe at creation, without specifying any data:

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

Upvotes: 9

Related Questions