Syntax for creating a new, empty geodataframe

1,299 views
Skip to first unread message

Dmitriy Tarasov

unread,
Aug 16, 2021, 8:53:44 AM8/16/21
to geopandas

I have a GeoDataFrame (let's call it Destinations) that was made using GeoPandas from a shapefile of point features. For every feature in Destinations, I need to find the nearest node on a graph and add that node to another GeoDataFrame (let's call it Destination_nodes). Presumably, I first need to create a blank GeoDataFrame called Destination_nodes and then, as I loop through Destinations, append each nearest node to it. But what is the syntax for creating a new, empty GeoDataFrame?

Martin Fleischmann

unread,
Aug 16, 2021, 6:13:20 PM8/16/21
to geop...@googlegroups.com
Hi, 

You should ideally pass columns to geopandas.GeoDataFrame to create an empty one and include “geometry” among them so that GeoPandas understands where the geometry will be. Ideally, you should also specify a CRS.

df = gpd.GeoDataFrame(columns=["foo", "bar", "geometry"], crs="EPSG:4326)

You can also use a different name for a geometry column but in that case you need to specify which of them will be an active geometry column.

df = gpd.GeoDataFrame(columns=["foo", "bar", "geom"], crs="EPSG:4326", geometry="geom")

M.

On 16 Aug 2021, at 13:53, Dmitriy Tarasov <dmitriy...@uconn.edu> wrote:


I have a GeoDataFrame (let's call it Destinations) that was made using GeoPandas from a shapefile of point features. For every feature in Destinations, I need to find the nearest node on a graph and add that node to another GeoDataFrame (let's call it Destination_nodes). Presumably, I first need to create a blank GeoDataFrame called Destination_nodes and then, as I loop through Destinations, append each nearest node to it. But what is the syntax for creating a new, empty GeoDataFrame?

--
You received this message because you are subscribed to the Google Groups "geopandas" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geopandas+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geopandas/16e5694f-219d-4563-85d6-6e9a3a9f2ca2n%40googlegroups.com.

Dmitriy Tarasov

unread,
Aug 20, 2021, 11:36:23 AM8/20/21
to geopandas
Thank you: I did define the geometry column as follows:
incident_nodes = gpd.GeoDataFrame(columns=["geometry"], crs="EPSG:2235"geometry="geometry")
and it seems to work.
Reply all
Reply to author
Forward
0 new messages