2

I have met with a problem when importing raster data of light intensity. Concretely, the following file contains raster data of Chinese nightlight intensity. I write the following command to import it:

file_temp = st_read(dsn = 'path/tif.gdb', layer = 'noflare_20131')

light = raster(file_temp)

plot(light)

link for replication data: https://www.dropbox.com/s/o8rn7cnb4a5rc6j/tif.gdb.zip?dl=0

However, it seems that I have only extracted an empty polygon into R without values of light intensity. In contrast, when importing the data into ArcGIS, it could be displayed successfully.

I guess that I should add some options to the command st_read() or raster() while have not figured out a specific solution.

2 Answers 2

3

The drivers in GDAL/OGR don't support rasters in FileGDB sources, and you should export from Arc in a different format, such as a GeoTIFF.

Command line tools show no layers for your FileGDB:

$ ogrinfo -al -so tif.gdb/
INFO: Open of `tif.gdb/'
      using driver `OpenFileGDB' successful.
$

So I am slightly surprised that R can read this:

> file_temp = st_read(dsn = './tif.gdb', layer = 'noflare_20131')
Reading layer `noflare_20131' from data source `/home/rowlings/Downloads/tif.gdb' using driver `OpenFileGDB'
Simple feature collection with 1 feature and 3 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 73.3875 ymin: 18.12917 xmax: 134.9875 ymax: 53.50417
geographic CRS: WGS 84

but it appears to be the raster bounds rather than the data itself:

> file_temp
Simple feature collection with 1 feature and 3 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 73.3875 ymin: 18.12917 xmax: 134.9875 ymax: 53.50417
geographic CRS: WGS 84
  RASTER FOOTPRINT_Length FOOTPRINT_Area                      FOOTPRINT
1   <NA>           193.95         2179.1 MULTIPOLYGON (((73.3875 18....

If there are any other vector layers in there, R can't list them and ogrinfo isn't showing them. If there are raster layers, GDAL can't read them.

More info here:

https://stackoverflow.com/questions/27821571/working-with-rasters-in-file-geodatabase-gdb-with-gdal

1

As of May 2023, GDAL can read gdb directories: https://github.com/OSGeo/gdal/pull/7389

The terra package is able to read these into R now, as far as I can make out:

library(terra)
file_temp = rast(dsn = 'path/tif.gdb', subds = 'noflare_20131')

I'm unable to get stars read_stars() to work with gdb directories, but there may be some workaround I'm unaware of

2
  • The st_read function does not come from terra but, rather sf. With a correct compile of GDAL, it has been able to read ESRI filegeodatabase files for some time, certainly pre-dating 2003 (because I have read them into R for several years via sf and previously rgdal). The GDAL compile that is default with sf has these gdb drivers. This pull was associated with adding the OpenFileGDB as opposed to the historically proprietary ESRI FileGDB API. Commented Jul 26 at 20:50
  • My mistake, it should be rast, not st_read; I copied the wrong line of code Commented Jul 26 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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