Select to view content in your preferred language

Reading and Writing Feature Class in a File Geodatabase Using Geopandas

4911
2
Jump to solution
02-03-2023 11:51 AM
tzz_12
by
Emerging Contributor

I am able to read and write shapefiles in ArcGIS Pro using geopandas, but it would be more useful to read and write within a geodatabase.  When I try to read a feature class in a file geodatabase, I get the following driver error: 

DriverIOError: Attempt to create csv layer (file) against a non-directory datasource.

When I try to write a geodataframe as a feature class, I get the following error:  

No such file or directory

I am wondering what I'm doing wrong... Please see my script below:  

file = outGDB + '\FC_Name'

FC_gdf = gp.read_file(file, driver = 'FileGDB'))  

FC_gdf = gp.to_file(file, driver = 'FileGDB')

Thanks for your help! 

0 Kudos
1 Solution

Accepted Solutions
dslamb2022
Occasional Contributor

I think this is an issue with having the FileGeodatabase drivers in a place that gdal / fiona can find it. Those two libraries are the backend for GeoPandas. You can get this setup, but it can be a pain to get it all working. For example: https://gis.stackexchange.com/questions/378890/adding-support-to-esris-filegdb-driver-when-fiona-gda...

Some other info: https://gdal.org/drivers/vector/filegdb.html#vector-filegdb

An alternative is to use the ArcGIS API for python and read and write a spatially enabled DataFrame. GeoPandas is better in a lot of ways, but SEDF generally works well with File Geodatabases and an ArcGIS Pro license: https://developers.arcgis.com/python/guide/part2-data-io-reading-data/

 

View solution in original post

0 Kudos
2 Replies
dslamb2022
Occasional Contributor

I think this is an issue with having the FileGeodatabase drivers in a place that gdal / fiona can find it. Those two libraries are the backend for GeoPandas. You can get this setup, but it can be a pain to get it all working. For example: https://gis.stackexchange.com/questions/378890/adding-support-to-esris-filegdb-driver-when-fiona-gda...

Some other info: https://gdal.org/drivers/vector/filegdb.html#vector-filegdb

An alternative is to use the ArcGIS API for python and read and write a spatially enabled DataFrame. GeoPandas is better in a lot of ways, but SEDF generally works well with File Geodatabases and an ArcGIS Pro license: https://developers.arcgis.com/python/guide/part2-data-io-reading-data/

 

0 Kudos
MikeMacRae
Frequent Contributor

I ran into this issue today and after sleuthing around, it looks like we are not providing the first parameters correctly in the geopandas.read_file() method. In the case of a geodatabse feature class as the path, you need to enter just the geodatabase as the path and point at particular feature classes using the layer parameter. i.e.

gdf = geopandas.read_file(r"C:\MyGeodatabase.gdb", layer="FeatureClassName", driver='OpenFileGDB')

 

This works fine for me. The only issue I can't seem to solve is to point at a feature class buried in a feature dataset.

0 Kudos