Newer
Older
library(nhdplusTools)
library(dplyr)
library(sf)
library(hyRefactor)
library(tidyr)
library(hyfabric)
rpu_vpu <- readr::read_csv(system.file("extdata/rpu_vpu.csv", package = "hyfabric"),
show_col_types = FALSE)
if(!exists("rpu_code")) {
if(exists("VPU")) {
vpu <- VPU
rpu_codes <- rpu_vpu[rpu_vpu$vpuid %in% vpu, ]$rpuid
rpu_code <- rpu_codes[1]
vpu <- get_rpu_dependent_vars()
rpu_code <- vpu$r
vpu <- vpu$v
if(!exists("vpu")) {
vpu <- get_rpu_dependent_vars(rpu_code)$v
if(!nchar(out_agg_gpkg <- Sys.getenv("OUT_GPKG")) > 5)
out_agg_gpkg <- file.path("cache", paste0(rpu_code, "_aggregate.gpkg"))
if(!nchar(out_refac_gpkg <- Sys.getenv("OUT_REFACTOR_GPKG")) > 5)
out_refac_gpkg <- file.path("cache", paste0(rpu_code, "_refactor.gpkg"))
if(!nchar(cache_split <- Sys.getenv("CACHE_SPLIT")) > 5)
cache_split <- file.path("temp", paste0(rpu_code, ".rda"))
if(!nchar(lookup_table_file <- Sys.getenv("LOOKUP_TABLE")) > 5)
lookup_table_file <- file.path("cache", paste0(rpu_code, "_lookup.csv"))
if(!nchar(lookup_table_file <- Sys.getenv("VPU_LOOKUP_TABLE")) > 5)
vpu_lookup_table_file <- file.path("cache", paste0("lookup_", vpu, ".csv"))
# Source Data
crs <- 5070
data_paths <- jsonlite::read_json(file.path("cache", "data_paths.json"))
nhdplus_path(data_paths$nhdplus_gdb)
suppressWarnings(staged_nhd <- stage_national_data())
nhd_flowline <- "nhd_flowline"
nhd_catchment <- "nhd_catchment"

Blodgett, David L.
committed
# Created and/or used during 02_Navigate
elev_diff <- 500 # Max difference in elevation within a single segment/POI
tt_diff <- 24 # Max number of hours between adjacent POIS
nav_gpkg <- file.path("cache", paste0("reference_", vpu,".gpkg"))
xwalk_layer <- paste0("HUC12_nhd_", vpu) # HUC12 - nhdcat crosswalk, built in Nav for VPU 20
nav_poi_layer <- paste0("POIs_tmp_", vpu) # Rolling Nav POI layer added to/modified througout nav workflow
WBs_layer <- paste0("WB_", vpu) # Waterbodies within VPU
poi_moved_layer <- paste0("POIs_mv_", vpu) # POIs moved from original COMID assignment
nsegments_layer <- paste0("nsegment_", vpu) # Minimally-sufficient network dissolved by POI_ID
pois_all_layer <- paste0("POIs_", vpu) # All POIs binded together
poi_xwalk_layer <- paste0("poi_xwalk_layer_", vpu) # POIs that changed COMIDS during the navigate part of the workflow
final_poi_layer <- paste0("final_POIS_", vpu)
split_meters <- 10000
combine_meters <- 1000
min_da_km <- 20

Blodgett, David L.
committed
# parallel factor for catchment reconciliation.

Blodgett, David L.
committed
nhd_outlet <- "nhd_outlet"
nhd_catchment <- "nhd_catchment"

Blodgett, David L.
committed
refactored_layer <- "collapsed"
reconciled_layer <- "reconciled"
divide_layer <- "divides"
agg_fline_layer <- "agg_fline"
agg_cats_layer <- "agg_cats"
outlets_layer <- "outlets"
lookup_table_gpkg <- paste0(rpu_code, "_lookup")
ND_gpkg <- file.path("cache", paste0("ND_", vpu,".gpkg"))
divides_xwalk <- paste0("divides_nhd_", vpu)
HRU_layer <- paste0("poi_cats_", vpu)
divides_nd <- paste0("divides_nd_", vpu)
missing_terms <- paste0("miss_terms_", vpu)
cat_boundary <- paste0("boundaries_", vpu)
missing_cats <- paste0("miss_cats_", vpu)
inc_pois_layer <- paste0("inc_POIs_", vpu) # layer of POIs used to derive first cut of segments
# Defined at various points for HI workflow
#raw_wbd <- paste0("HU12_", VPU) # Raw HUC12
#gage_loc <- paste0("GageLoc_", VPU) # HI GageLoc
#TE <- paste0("TE_", VPU) # Thermo-electric
#NID_layer <- paste0("NID_", VPU) # Raw NID points
#gage_events_layer <- paste0("gage_events_", VPU) # gages with flowline index information for possible splitting
# not used?
# huc12_xWalk <- file.path(data_paths$nhdplus_dir, "CrosswalkTable_NHDplus_HU12.csv")
# HUC12 <- file.path(data_paths$nhdplus_dir, "HUC12.rds")