From f0fef4124d55aa4a19c996992f52f342b5e1cb79 Mon Sep 17 00:00:00 2001 From: Bock <abock@usgs.gov> Date: Mon, 8 May 2023 10:00:38 -0600 Subject: [PATCH] Handling of split cats better --- workspace/06-1_hyRefactor_cats.Rmd | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/workspace/06-1_hyRefactor_cats.Rmd b/workspace/06-1_hyRefactor_cats.Rmd index 58c02af..6f3554b 100644 --- a/workspace/06-1_hyRefactor_cats.Rmd +++ b/workspace/06-1_hyRefactor_cats.Rmd @@ -24,6 +24,9 @@ source("R/utils.R") source("R/config.R") source("R/NHD_navigate.R") source("R/hyRefactor_funs.R") + +old_path <- Sys.getenv("PATH") +Sys.setenv(PATH = paste(old_path, "C:\\Users\\abock\\AppData\\Roaming\\npm", sep = ";")) ``` This reconcile-catchments step splits and combines catchment boundaries according to the process that was completed in refactor flines. @@ -33,13 +36,12 @@ if(needs_layer(out_refac_gpkg, divide_layer)) { rpu_string <- paste0("rpu_", rpu_code) fdr <- data_paths$fdr[[rpu_string]] fac <- data_paths$fac[[rpu_string]] - + fdr_temp <- terra::rast(fdr) raster_crs <- terra::crs(fdr_temp) # reconciled have no ID applied in refactoring flowlines - reconciled <- st_transform(read_sf(out_refac_gpkg, reconciled_layer), raster_crs) - + reconciled <- st_transform(read_sf(out_refac_gpkg, reconciled_layer), raster_crs) # refactored has the original COMIDs and other attributes refactored <- st_transform(read_sf(out_refac_gpkg, refactored_layer), raster_crs) %>% distinct(.keep_all = T) @@ -51,25 +53,23 @@ if(needs_layer(out_refac_gpkg, divide_layer)) { fline_rec = reconciled, fdr = fdr, fac = fac, - para = para_reconcile, + para = para_reconcile, cache = cache_split, - keep = NULL) - + keep = NULL) if(exists("divides")) { - + load(cache_split) - - split_cats <- bind_rows(split_cats) - + + split_cats <- bind_rows(split_cats[lengths(split_cats) > 0]) + split_cats$areasqkm <- as.numeric(units::set_units(sf::st_area(split_cats), "km^2")) - + write_sf(sf::st_transform(split_cats, crs), out_refac_gpkg, split_divide_layer) - - unlink(cache_split) - + } + unlink(cache_split) write_sf(sf::st_transform(divides, crs), out_refac_gpkg, divide_layer) } -- GitLab