I would like to open a .gdb
file which I received as .tar.gdb
. The unzipped folder contains the following elements in the figure. How can I open this in R
? It is a raster digital elevation model. I need the elevation values of the raster cells but do not have ArcGIS or related programs on my computer 1.
3 Answers 3
gdb files are ESRI GeoDatabase files, a proprietary format not suited for exchange with other applications.
Versions of GDAL before 3.7 have no GDAL raster driver for ESRI GeoDatabase files, and since R uses GDAL to load raster data, this won't work. If you have GDAL version 3.7 or more you should have the driver. This version was released in May 2023 but its possible your version is old. Even the latest rocker/geospatial:latest docker image is currently only linked with GDAL 3.4.1.
-
2File geodatabase hasn't changed format since the 9.3-10.0 reorganization to XML metadata. The read/write Esri FGDB API does not support pre-10 layout, but the read-only open API does. Neither supports rasters.Vince– Vince2020年05月01日 12:22:36 +00:00Commented May 1, 2020 at 12:22
-
1Very outdated answer. QGIS can open .gdb files directly now, so it should be possible in R too!Tomas– Tomas2024年03月17日 22:34:17 +00:00Commented Mar 17, 2024 at 22:34
-
@Tomas Really? What version of QGIS? Because the latest Ubuntu on my system only has GDAL 3.4.1 and that can't read rasters from an ESRI gdb. Perhaps you have >= 3.7Spacedman– Spacedman2024年03月19日 15:12:09 +00:00Commented Mar 19, 2024 at 15:12
-
@Spacedman QGIS 3.16.4-Hannover, Compiled against GDAL/OGR 3.1.4.Tomas– Tomas2024年07月02日 07:02:56 +00:00Commented Jul 2, 2024 at 7:02
As an update to @Spacedman's answer regarding vector files, the terra::vect
function makes reading .gdb files very easy for these filetypes:
DATA <- vect("/Path/File.gdb")
If the .gdb has multiple layers, there is also a layer
argument to specify which one you want. Otherwise it just defaults to the first layer alphabetically.
SO Questions related to the OP's issue: Importing raster with R from File Geodatabase? and How to extract raster from .gdb instead of empty polygons?
As of June 2025, you can absolutely access raster data in a geodatabase (and without any proprietary ESRI software required)! You will need to have the latest spatial packages installed (if you need older versions, this may be less helpful for you), and in my case this worked on a Macbook using homebrew. I installed GDAL, GEOS, and PROJ (e.g., 'brew install gdal' after homebrew is set up). After this is done, make sure R is up to date, and then install terra (and sf, etc. if you want them) from source by running the below in R Studio or equivalent:
install.packages("terra", type = "source")
This will ensure that terra, etc., are linked properly with the spatial packages on your system (i.e., the homebrew installs). This step is really important; personally I have had the most sucess with doing installs from source rather than in the built-in R Studio package update manager.
Once this is done, you should be able to import the raster(s) you need from a geodatabase as follows:
gdb_path <- "/Users/your_user/Documents/your_dir/your_project.gdb"
your_raster <- rast(gdb_path, subds = "your_raster_layer")
.tar.gdb
, but it seems to have extracted correctly (FGDB is not a file format, but a directory of file contents, as opposed to RDBMS tables). That's the good news. The bad news is that rasters are not directly supported by either the Esri or Open file geodatabase drivers. There may be some reverse-engineered extraction tools but you'd probably be better off with alternate input.