Skip to content

Instantly share code, notes, and snippets.

@mhweber
Last active November 7, 2022 18:51
Show Gist options
  • Select an option

  • Save mhweber/de512563a5ba02fe38b5074c97e018d0 to your computer and use it in GitHub Desktop.

Select an option

Save mhweber/de512563a5ba02fe38b5074c97e018d0 to your computer and use it in GitHub Desktop.
Download all StreamCat metrics for specific state or hydroregion
library(RCurl)
library(stringr)
url <- "https://gaftp.epa.gov/EPADataCommons/ORD/NHDPlusLandscapeAttributes/StreamCat/States/" # can use hydro dir here instead
filenames <- getURL(url, userpwd="", ftp.use.epsv = FALSE, verbose=FALSE,dirlistonly = TRUE, ssl.verifypeer = FALSE)
destnames <- strsplit(filenames, "\r*\n")[[1]]
destnames = destnames[grep("_OR.zip", destnames)] # different state - or hydroregion if in hydroregion directory
setwd('somedir/subdir') # where you want to download
for (d in destnames){
d <- str_match_all(d, "href=\"(.*?)\"")
d <- d[[1]][2]
download.file(paste0(url,d),d)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment