I have a feature contained in a geodatabase that is larger than 2GB as an exported shapefile. I need to run an extract function in R to attribute the polygons with data from a raster file. Exporting the feature as a table is not a solution. How can I read feature classes contained within an Esri file geodatabase?
2 Answers
You can use rgdal to access feature classes in Esri file geodatabases.
require(rgdal) # The input file geodatabase fgdb <- "C:/path/to/your/filegeodatabase.gdb" # List all feature classes in a file geodatabase subset(ogrDrivers(), grepl("GDB", name)) fc_list <- ogrListLayers(fgdb) print(fc_list) # Read the feature class fc <- readOGR(dsn=fgdb,layer="some_featureclass") # Determine the FC extent, projection, and attribute information summary(fc) # View the feature class plot(fc) - 2Previously, you could only do this if you downloaded the ESRI filegeodatabase API and compiled GDAL against it. If you use OSGeo4W to install GDAL there is an option to do this automatically. However, this may have changed in later releases of GDAL and it could now be native so, if I am incorrect I apologize.Jeffrey Evans– Jeffrey Evans2015-06-19 20:00:09 +00:00Commented Jun 19, 2015 at 20:00
- 3@JeffreyEvans This is native now.2015-06-19 20:04:50 +00:00Commented Jun 19, 2015 at 20:04
- 4While it is native for windows, it does not seem to be included currently for other platforms (at least Debian Jessie).Cotton.Rockwood– Cotton.Rockwood2016-04-04 03:21:53 +00:00Commented Apr 4, 2016 at 3:21
- 2+1 Works nicely. It helps to know that the
layerargument may be omitted when there is just one feature class in the GDB.whuber– whuber2018-05-08 20:29:36 +00:00Commented May 8, 2018 at 20:29 - 4For those who know nothing about
gdbfiles,fgdbin this answer here is a directory andogrListLayers()works on this directory...MichaelChirico– MichaelChirico2018-12-07 08:26:34 +00:00Commented Dec 7, 2018 at 8:26
As already posted in this answer, this now also works very nicely with sf:
require(sf) fc <- sf::st_read("C:/path/to/your/filegeodatabase.gdb", layer = "some_featureclass") Writing to a fgdb is now implemented as well
st_drivers()$write[st_drivers()$long_name == "ESRI FileGDB"] #> [1] TRUE - 1Writing is now implemented for gdal.org/drivers/vector/filegdb.html#vector-filegdb But, true to ESRI with the caveat: "The FileGDB SDK API does not allow to create a feature with a FID specified by the user. Starting with GDAL 2.1, the FileGDB driver implements a special FID remapping technique to enable the user to create features at the FID of their choice."Jeffrey Evans– Jeffrey Evans2022-06-15 19:16:05 +00:00Commented Jun 15, 2022 at 19:16