Skip to content
Snippets Groups Projects
Commit 8e1e541c authored by Bock, Andy's avatar Bock, Andy
Browse files

Fixes to wb inlets, term POIs

parent d582005f
No related branches found
No related tags found
1 merge request!154Waterbody inlet handling/terminal POIs
......@@ -50,7 +50,8 @@ atts <- readRDS(file.path(data_paths$nhdplus_dir, "nhdplus_flowline_attributes.r
# Derive or load HUC12 POIs
if(needs_layer(temp_gpkg, nav_poi_layer)) {
nhd <- read_sf(nav_gpkg, nhd_flowline)
nhd <- read_sf(nav_gpkg, nhd_flowline) %>%
distinct()
try(nhd <- select(nhd, -c(minNet, WB, struct_POI, struct_Net, POI_ID)), silent = TRUE)
# HUC02 includes some
......@@ -495,12 +496,12 @@ mapview(filter(tmp_POIs, Type_Travel == 1), layer.name = "Travel time break POIs
if(needs_layer(temp_gpkg, pois_all_layer)) {
unCon_POIs <- filter(st_drop_geometry(filter(nhd, minNet == 1)), COMID %in% tmp_POIs$COMID, AreaSqKM == 0)
check <- filter(tmp_POIs, COMID %in% unCon_POIs$COMID)
#check <- filter(tmp_POIs, COMID %in% unCon_POIs$COMID)
# If any POIs happened to fall on flowlines w/o catchment
if (nrow(unCon_POIs) >0){
# For confluence POIs falling on Flowlines w/o catchments, derive upstream valid flowline,
poi_fix <- DS_poiFix(filter(tmp_POIs, nexus == FALSE), filter(nhd, dend == 1))
poi_fix <- DS_poiFix(tmp_POIs, filter(nhd, dend == 1))
new_POIs <- st_compatibalize(poi_fix$new_POIs, tmp_POIs)
xWalk <- poi_fix$xWalk
......
......@@ -86,7 +86,7 @@ if(needs_layer(out_refac_gpkg, refactored_layer)) {
# Select controls whether prepare_nhdplus is used.
refactor_nhdplus(nhdplus_flines = dplyr::select(nhdplus_flines, -FTYPE),
split_flines_meters = split_meters,
split_flines_cores = para_split_flines,
split_flines_cores = para_reconcile,
collapse_flines_meters = combine_meters,
collapse_flines_main_meters = combine_meters,
out_refactored = tf,
......
......@@ -310,7 +310,7 @@ DS_poiFix <- function(POIs_wgeom, nhd){
inner_join(select(st_drop_geometry(nhd), COMID, Hydroseq), by = c("DnHydroseq" = "Hydroseq"))
# Find segments with POIs where there is no corresponding catchment that are not terminal
unCon_POIs <- filter(nhd, COMID %in% POIs$COMID, AreaSqKM == 0 & Hydroseq != TerminalPa)
unCon_POIs <- filter(nhd, COMID %in% POIs$COMID, AreaSqKM == 0)# & Hydroseq != TerminalPa)
poi_fix <- as.data.frame(do.call("rbind", lapply(unCon_POIs$COMID, movePOI_NA_DA, st_drop_geometry(nhd)))) %>%
inner_join(POIs, by = c("oldPOI" = "COMID")) %>%
......@@ -1009,8 +1009,9 @@ WB_event <- function(WBs, nhd_wb, type){
wb_events <- get_flowline_index(nhd_wb, inlet_pnts) %>%
inner_join(select(st_drop_geometry(nhd_wb), COMID, WBAREACOMI, LevelPathI), by = "COMID") %>%
mutate(event_type = type) %>%
inner_join(select(inlet_pnts, LevelPathI), by = "LevelPathI") %>%
select(-LevelPathI) %>%
inner_join(select(inlet_pnts, LevelPathI, WB_COMID = COMID), by = "LevelPathI") %>%
mutate(WBAREACOMI = WB_COMID) %>%
select(-c(LevelPathI, WB_COMID)) %>%
st_as_sf()
}
return(wb_events)
......@@ -1168,7 +1169,9 @@ wbin_POIcreation <- function(nhd, WBs_VPU, data_paths, crs, split_layer){
# (outlets should already be defined)
nhd_WBs <- data.frame()
if(is.list(WBs_VPU_areaHR)) {
nhd_WBs <- filter(nhd, minNet == 1 & COMID %in% WBs_VPU_areaHR$wb_table$comid)
nhd_WBs <- filter(nhd, minNet == 1,
COMID %in% WBs_VPU_areaHR$wb_table$comid,
AreaSqKM > 0)
}
if(nrow(nhd_WBs) > 0){
......@@ -1185,9 +1188,20 @@ wbin_POIcreation <- function(nhd, WBs_VPU, data_paths, crs, split_layer){
st_compatibalize(tmp_POIs) %>%
mutate(nexus = TRUE)
tmp_POIs <- data.table::rbindlist(list(tmp_POIs,
select(wb_inlet_events, COMID, Type_WBIn = WBAREACOMI, nexus)), fill = TRUE) %>%
st_as_sf()
wb_inlet_POIs <- filter(wb_inlet_events, REACH_meas < 5) %>%
select(COMID, Type_WBIn = WBAREACOMI, nexus)
tmp_POIs <- addType(select(wb_inlet_POIs, COMID, Type_WBIn),
tmp_POIs, "WBIn")
wb_inlet_events <- filter(wb_inlet_events, !COMID %in% wb_inlet_POIs$COMID)
if(nrow(wb_inlet_POIs) != nrow(wb_inlet_events)){
tmp_POIs <- data.table::rbindlist(list(tmp_POIs,
select(wb_inlet_events, COMID, Type_WBIn = WBAREACOMI, nexus) %>%
filter(!COMID %in% tmp_POIs$COMID)), fill = TRUE) %>%
st_as_sf()
}
return(list(POIs = tmp_POIs, events = wb_inlet_events))
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment