nate
nate

Reputation: 1244

Cannot open data source. .GDB in R

I am trying to load the data from the National Address Database provided by Transportation.gov into R. The data can be downloaded by anyone after accepting the disclaimer at this link: https://www.transportation.gov/gis/nad/disclaimer

I download the data, unzipped it into a directory I called data and then tried to use rgdal to list all the layers present in the data via:

fc_list<- rgdal::ogrListLayers("./data/NAD_20180215.gdb").

However, I cannot get rgdal to return anything other than an error saying "Cannot Open Data Source"....

I am wondering how I would go about listing the layers present in the .gdb folder as well as reading them into R?

I'm very grateful for any help. Thank you in advance.

-nate

Upvotes: 0

Views: 1325

Answers (2)

paths in mac are written differently.

https://rpubs.com/bpattiz/Directories_Paths_Workspaces

And especially:

https://derekyves.github.io/2016/05/10/codeshare.html

First you need to set your working directory.

And then probably:

fc_list<- rgdal::ogrListLayers("/data/NAD_20180215.gdb")

or

fc_list<- rgdal::ogrListLayers("~/data/NAD_20180215.gdb")

will work

Upvotes: 0

nya
nya

Reputation: 2250

Following the suggestion here, using a full path to the gdb folder helped in my case.

# check for package and install if needed
if(!require(rgdal)){
    install.packages("rgdal", dep=T)
    library(rgdal)
}

# full path to the geodatabase required
fgdb <- "C:/full/path/to/the/geodatabase.gdb"

# list all feature classes in a file geodatabase
subset(ogrDrivers(), grepl("GDB", name))
ogrListLayers(fgdb)

Upvotes: 1

Related Questions