10

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?

3 Answers 3

7

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") 
2
  • thanks for the response. Took a while to realize that I could get the FileGDB.dll file and installation through GIS Internals, rather than the ESRI route (which didn't work for me). Perhaps another thing to add is that you can overwrite a layer in a GDB, simply by adding specifying the layer target layer.to_file("result.gdb", layer="layer_name", driver="FileGDB"). Commented Mar 10, 2017 at 13:32
  • 1
    For that I get Unsupported Driver
    – user32882
    Commented May 2, 2019 at 9:40
1

This question is quite old, but if you (or anyone) is looking for a hint, the newer ArcGIS desktop software (Pro) leverages NumPy structured arrays internally (that is, you can run it from inside a Jupyter Notebook or command line, etc.) within Pro.

The NumPyArrayToFeatureClass function might be useful. For strictly tabular data that you want to store in an Esri geodatabase, there is the NumPyArrayToTable function.

I would recommend if converting from geopandas to a NumPy array, be sure to declare the dype for each column, to avoid an error that Esri can throw when converting an object dtype to a string.

It's not a bad practice, in any event, so that when you copy rows/features to the geodatabase, the data types are what you expect.

-2

Have you seen this page from the USGS? It describes how to move tabular data back to a gdb using ArcPy. You might be able to tweak that...

It looks like geopandas does not write to GDB, due to that being an Esri proprietary format. You can run

import fiona pprint(fiona.supported_drivers)

to get the supported formats geopandas can write to:

 'ARCGEN': 'r',
 'AeronavFAA': 'r',
 'BNA': 'raw',
 'DGN': 'raw',
 'DXF': 'raw',
 'ESRI Shapefile': 'raw',
 'GPSTrackMaker': 'raw',
 'GPX': 'raw',
 'GeoJSON': 'rw',
 'Idrisi': 'r',
 'MapInfo File': 'raw',
 'OpenFileGDB': 'r',
 'PCIDSK': 'r',
 'SEGY': 'r',
 'SUA': 'r'

Would it be feasible for your process to export to a shapefile and then use arcpy.FeatureClassToGeodatabase_conversion to bring that into your GDB?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.