Last active
July 6, 2021 20:05
-
-
Save mhweber/798347edefc975ed6a7b7e4a0134af62 to your computer and use it in GitHub Desktop.
Download StreamCat metric file for a state and subset to counties of interest
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(sf) | |
| library(tigris) | |
| setwd('H:/WorkingData') | |
| temp <- tempfile() | |
| download.file("https://gaftp.epa.gov/EPADataCommons/ORD/NHDPlusLandscapeAttributes/StreamCat/States/ImperviousSurfaces2006_WA.zip",temp) | |
| wa <- read.csv(unz(temp, "ImperviousSurfaces2006_WA.csv")) | |
| unlink(temp) | |
| counties <- counties("Washington", cb = TRUE) | |
| counties <- counties[counties$NAME %in% c('Kitsap','King','Pierce','Jefferson','Snohomish'),] | |
| # get NHDPlus catchments - all of WA is in NHDPlus region 17 | |
| cats <- st_read('L:/Priv/CORFiles/Geospatial_Library/Data/RESOURCE/PHYSICAL/HYDROLOGY/NHDPlusV21/NHDPlusPN/NHDPlus17/NHDPlusCatchment/Catchment.shp') | |
| # subset catchments to just counties of interest | |
| # align CRS | |
| counties <- st_transform(counties, st_crs(cats)) | |
| ggplot(counties) + | |
| geom_sf() + | |
| ggtitle("Counties in WA") + | |
| theme_bw() | |
| county_cats <- cats[counties,] | |
| # Now subset the StreamCat metric file | |
| wa_counties_imperv <- wa[wa$COMID %in% county_cats$FEATUREID,] | |
| head(wa_counties_imperv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment