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?
Asked
Active
Viewed 3.9k times
2 Answers
53
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)
Aaron
- 51,658
- 28
- 154
- 317
25
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
Ratnanil
- 983
- 8
- 20
-
Writing is now implemented for https://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 Jun 15 '22 at 19:16
layerargument may be omitted when there is just one feature class in the GDB. – whuber May 08 '18 at 20:29gdbfiles,fgdbin this answer here is a directory andogrListLayers()works on this directory... – MichaelChirico Dec 07 '18 at 08:26