From 27ada9f3bbc022c0f533f41fbf63362de00bbfd2 Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Mon, 16 Oct 2023 16:46:49 -0500 Subject: [PATCH] added layers variable to 2nd script --- 02_process_data.R | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/02_process_data.R b/02_process_data.R index 672ac62..0a06587 100644 --- a/02_process_data.R +++ b/02_process_data.R @@ -1,4 +1,5 @@ # load libraries +library(nhdplusTools) library(sf) # reload extent data so you don't need to run the download data script again @@ -9,30 +10,34 @@ extent <- read.csv(file = "extent.csv") crs <- 4269 extent_poly <- st_polygon( - x = list( - cbind( - extent$longitude[c(1,2,2,1,1)], - extent$latitude[c(1,1,2,2,1)]) - ) +x = list( + cbind( + extent$longitude[c(1,2,2,1,1)], + extent$latitude[c(1,1,2,2,1)]) +) ) extent_poly <- st_sfc(extent_poly, crs=4326) extent_bbox <- st_bbox(st_transform(x = extent_poly, crs)) extent <- list(longitude_max = max(extent$longitude), - longitude_min = min(extent$longitude), - latitude_max = max(extent$latitude), - latitude_min = min(extent$latitude)) + longitude_min = min(extent$longitude), + latitude_max = max(extent$latitude), + latitude_min = min(extent$latitude)) # load and crop hydrologic data data <- list(NULL) sf_use_s2(FALSE) +layers <- c("NHDArea", + "NHDFlowline", + "NHDWaterbody", + "NHDPlusLandSea") for (layer in layers){ - data[[layer]] <- st_crop(st_read(paste0(nhdplusTools_data_dir(),"/data.gpkg"), layer = layer), y = extent_bbox) +data[[layer]] <- st_crop(st_read(paste0(nhdplusTools_data_dir(),"/data.gpkg"), layer = layer), y = extent_bbox) } # load political boundaries political <- list(NULL) political_boundaries <- list.files(path = paste0(data_dir, "/political_boundaries")) for (boundary in political_boundaries) { - political[[boundary]] <- st_read(paste0(data_dir, "/political_boundaries/", boundary)) +political[[boundary]] <- st_read(paste0(data_dir, "/political_boundaries/", boundary)) }