Last active
November 7, 2022 18:51
-
-
Save mhweber/de512563a5ba02fe38b5074c97e018d0 to your computer and use it in GitHub Desktop.
Download all StreamCat metrics for specific state or hydroregion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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