I would like to learn to batch import from many geodatabases at once and merge the files together into a new unified shapefile. All of the GDBs and Features have a similar name and file structure. For example GDB1, GDB2, GDB3,...ect. and inside each have shp1, shp2, and shp3.....ect.

From other posts in the group I learned that if these features were not withing GDBs I could simply create a list of the files....

shp_files <- list.files(wd,  pattern = glob2rx("*.shp")

and then use rbind and lapply to merge them together....

merged<-do.call(rbind, lapply(shp_files, rgdal::readOGR))

But how can I alter this code to work if the files are in a GDB or if the bundle of features are in a zipped folder?

  • 1
    You've named your feature classes "shp1, shp2, shp3..."? That's mighty confusing. Shapefiles are a file-based data format. File geodatabase is a completely different file-based format. You cannot store shapefiles in a file geodatabase, only convert them to FGDB tables. – Vince Jun 18 '19 at 2:30
  • Ahh.. thank you! I didn’t know that. I think part of the reason I am not finding code for this online is I am not using the right terminology. Also... yes it’s basically named that way, and I just wanted to use the most simple example. – Phillip Mohebalian Jun 18 '19 at 15:55

This should get you started with reading in all of your feature classes, then you can perform a similar operation to what you've included in your question.

path<-"C:/Users/GIS Data/Some Folder/your.gdb"

st_layers will list all of the names within your gdb which we are then passing to purrr::map which takes the list of names and for each name will read that into R from your gdb.

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.