[GIS] Geopandas: Write layer back into GeoDataBase

file-geodatabasefionageopandaspandaspython

I use geopandas (which uses fiona) to read a GeoDataBase layer (using driver="OpenFileGDB") into a geodataframe for easy manipulation.

read_shp = gpd.read_file(GDB_file, layer=layer_choice)

That works well. I then rearrange the columns and do some data manipulation until I am happy with the data.

BUT I have no idea or if it is possible to write that geodataframe back into the GeoDataBase?

I tried:
read_shp.to_file(GDB_file, layer=layer_choice)
But that just creates a new shapefile in the wrong place.

Does anyone have a solution to this problem?

Best Answer

As with Fiona where you can specify the driver when you save a layer, you can do the same thing with GeoPandas (Writing Spatial Data)

GeoDataFrames can be exported to many different standard formats using the GeoDataFrame.to_file() method. For a full list of supported formats, type import fiona; fiona.supported_drivers.

In my case:

fiona.supported_drivers
{'ESRI Shapefile': 'raw', 'OpenFileGDB': 'r', ..., 'FileGDB': 'raw',...}
  • The OpenFileGDB driver is Read-only ('r', provides only read access to File Geodatabases)

  • If you want read and write access, you need to use the FileGDB driver ('raw')

If the driver is not installed, a solution is given in How to add support for FileGDB (Esri file gdb API) driver in fiona?

layer.to_file("result.gdf",driver="FileGDB")