0

I recently updated R and all of it's packages, and my code for reading in the layers of a geodatabase no longer works.

It works fine on my windows desktop, but doesn't work on my macbook (I change the filepath for the appropriate machine).

I get the same behaviour with any shapefile or geodatabase at any file path.

I'm essentially following the instructions listed here: https://stackoverflow.com/questions/52340442/cannot-open-data-source-gdb-in-r

r1_gdb <-  "/Volumes/LaCie/2019 PRISM GIS clean/Region1_Cleaned.gdb"

subset(ogrDrivers(), grepl("GDB", name)) 
          name    long_name write  copy isVector
50 OpenFileGDB ESRI FileGDB FALSE FALSE     TRUE

r1_lyrlist <- ogrListLayers(r1_gdb)

Error in ogrListLayers(r1_gdb) : Cannot open data source

What strikes me as weird is that the results of other functions leads me to believe this should be working fine.

file.exists(r1_gdb)
[1] TRUE

list.files(r1_gdb)
 [1] "a00000001.freelist"                         
 [2] "a00000001.gdbindexes"                       
 [3] "a00000001.gdbtable"                         
 [4] "a00000001.gdbtablx"    
.....

Here is info about my version of GDAL on my macbook.

> library(rgdal)
rgdal: version: 1.5-19, (SVN revision 1092)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.1.4, released 2020/10/20
Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgdal/gdal
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgdal/proj
Linking to sp version:1.4-4
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
> getGDALVersionInfo()
[1] "GDAL 3.1.4, released 2020/10/20"

It works fine on my windows desktop. It seems I have a different version of GDAL on the two computers. But it's the windows computer with the older version of GDAL where the code doesn't work.

> library(rgdal)
Loading required package: sp
rgdal: version: 1.5-21, (SVN revision 1105)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
Path to GDAL shared files: C:/Users/andersonch/Documents/R/win-library/4.0/rgdal/gdal
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
Path to PROJ shared files: C:/Users/andersonch/Documents/R/win-library/4.0/rgdal/proj
Linking to sp version:1.4-5
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.

Any suggestions as to what I should investigate?

6
  • Can you simplify this down to one ogrListLayers call on a single folder that is a GDB data source? The lapply over a list of them might be clouding the issue.
    – Spacedman
    Jan 25, 2021 at 14:59
  • OK, sure. I've edited the question accordingly. The same behaviour happens. Jan 25, 2021 at 15:35
  • Oh, does the subset(ogrDrivers... not return anything? This means your OGR/GDAL doesn't have GDB drivers. What operating system and version of everything are you on? What does getGDALVersionInfo() say? How did you install everything?
    – Spacedman
    Jan 25, 2021 at 18:05
  • ya, I always thought it was weird that subset(ogrDrivers) didn't return any output. I included it because I was following the code from the linked answer above, but I never understood what it did because I never saw an output, even when this code used to work Jan 25, 2021 at 18:30
  • Looks like you're on a Mac, which I don't really do, so I think I'll have to leave it for the Mac experts. You might want to list the full, unfiltered output of ogrDrivers() here too.
    – Spacedman
    Jan 25, 2021 at 19:11

1 Answer 1

2

Had the same issue but got a solution by using the file's absolute path. First, get the absolute path using the tools package.

library(tools)
r1_gdb <- file_path_as_absolute("/Volumes/LaCie/2019 PRISM GIS clean/Region1_Cleaned.gdb")

Then run the ogrListLayers function.

r1_lyrlist <- ogrListLayers(r1_gdb)

That should work.

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.