I have a list of dataframes, all of the same structure and all are polygons.
How can I add them all together using geopandas?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityit seems that this is the right way to do that right now:
rdf = gpd.GeoDataFrame( pd.concat( dataframesList, ignore_index=True) )
rdf = gpd.GeoDataFrame(pd.concat(dataframesList, ignore_index=True), crs=dataframesList[0].crs)
. Now new dataframe will also have the same CRS as one of the initial dataframes. Because of using pandas.concat
any geographical metadata such as CRS does not get preserved by default.
I just experimented with this - maybe in GeoPandas 0.2.1 and Pandas 0.20.3 it is a bit more concise:
gdf = pd.concat([gdf1, gdf2])
gdf is automatically created as a GeoDataFrame. Of course if there is a chance of conflicting indices you'll want to keep the 'ignore_index=True' parameter.
gdf1.to_file(xxx, driver='ESRI Shapefile')
you will get an error which says 'DataFrame' object has no attribute 'to_file'