36

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 2

48

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)
5
  • 2
    Previously, 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. Jun 19, 2015 at 20:00
  • 3
    @JeffreyEvans This is native now.
    – Aaron
    Jun 19, 2015 at 20:04
  • 4
    While it is native for windows, it does not seem to be included currently for other platforms (at least Debian Jessie). Apr 4, 2016 at 3:21
  • 2
    +1 Works nicely. It helps to know that the layer argument may be omitted when there is just one feature class in the GDB.
    – whuber
    May 8, 2018 at 20:29
  • 4
    For those who know nothing about gdb files, fgdb in this answer here is a directory and ogrListLayers() works on this directory... Dec 7, 2018 at 8:26
21

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")

But writing into a fgdb ist not implemented (yet?), you'd have to have a ArcGIS / ArcMap License as well as the R library arcgisbinding (see https://github.com/R-ArcGIS/r-bridge)

st_drivers()$write[st_drivers()$long_name == "ESRI FileGDB"]
#> [1] FALSE
1
  • Writing 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." Jun 15 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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