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

Merge branch 'main' into 'main'

Clean up and fix issues in reference flowline creation

See merge request !171
parents ce53f946 fc5fe2b0
No related branches found
No related tags found
1 merge request!171Clean up and fix issues in reference flowline creation
...@@ -278,7 +278,7 @@ if(!file.exists(ref_cat)){ ...@@ -278,7 +278,7 @@ if(!file.exists(ref_cat)){
for (vpu in possible_vpu){ for (vpu in possible_vpu){
vpu_gpkg <- paste0(vpu, "_reference_features.gpkg") vpu_gpkg <- paste0(vpu, "_reference_features.gpkg")
sbtools::item_file_download("61295190d34e40dd9c06bcd7", names = vpu_gpkg, sbtools::item_file_download("6317a72cd34e36012efa4e8a", names = vpu_gpkg,
destinations = file.path(ref_fab_path, vpu_gpkg)) destinations = file.path(ref_fab_path, vpu_gpkg))
} }
...@@ -545,22 +545,6 @@ out_list <- c(out_list, out) ...@@ -545,22 +545,6 @@ out_list <- c(out_list, out)
``` ```
```{r nhdplus_attributes}
out <- list(new_nhdp_atts = file.path("cache", (sb_f <- "enhd_nhdplusatts.csv")))
if(!file.exists(out$new_nhdp_atts)) {
if(is.null(sbtools::current_session()))
authenticate_sb()
sbtools::item_file_download("63cb311ed34e06fef14f40a3",
names = sb_f,
destinations = out$new_nhdp_atts)
}
out_list <- c(out_list, out)
```
```{r GFv1.1} ```{r GFv1.1}
GFv11_dir <- file.path(data_dir, "GFv11") GFv11_dir <- file.path(data_dir, "GFv11")
out <- list(GFv11_gages_lyr = file.path(data_dir, "GFv11/GFv11_gages.rds"), out <- list(GFv11_gages_lyr = file.path(data_dir, "GFv11/GFv11_gages.rds"),
......
...@@ -260,7 +260,7 @@ if(!"Type_WBOut" %in% names(tmp_POIs)) { ...@@ -260,7 +260,7 @@ if(!"Type_WBOut" %in% names(tmp_POIs)) {
tmp_POIs <- read_sf(temp_gpkg, nav_poi_layer) tmp_POIs <- read_sf(temp_gpkg, nav_poi_layer)
nhd <- read_sf(nav_gpkg, nhd_flowline) nhd <- read_sf(nav_gpkg, nhd_flowline)
ref_WB <- read_sf(temp_gpkg, WBs_layer) ref_WB <- read_sf(temp_gpkg, WBs_layer)
resops_POIs_df <- read.csv(file.path("data/reservoir_Data", paste0("resops_POIs_",vpu,".csv"))) resops_POIs_df <- read.csv(file.path("data/reservoir_Data", paste0("resops_POIs_", VPU,".csv")))
} }
mapview(filter(tmp_POIs, !is.na(Type_WBOut)), layer.name = "Waterbody outlet POIs", col.regions = "red") mapview(filter(tmp_POIs, !is.na(Type_WBOut)), layer.name = "Waterbody outlet POIs", col.regions = "red")
......
...@@ -183,7 +183,7 @@ if(needs_layer(out_refac_gpkg, outlets_layer)) { ...@@ -183,7 +183,7 @@ if(needs_layer(out_refac_gpkg, outlets_layer)) {
check_dups_poi <- final_outlets %>% check_dups_poi <- final_outlets %>%
group_by(reconciled_ID) %>% group_by(reconciled_ID) %>%
filter(n() > 1) %>% filter(n() > 1) %>%
ungroup ungroup()
if(nrow(check_dups_poi) > 1){ if(nrow(check_dups_poi) > 1){
print("Double-check for double POIs") print("Double-check for double POIs")
......
...@@ -92,7 +92,7 @@ if(needs_layer(out_agg_gpkg, agg_cats_layer)){ ...@@ -92,7 +92,7 @@ if(needs_layer(out_agg_gpkg, agg_cats_layer)){
mutate(type = ifelse(type == "terminal" & !is.na(toID), "outlet", type)) %>% mutate(type = ifelse(type == "terminal" & !is.na(toID), "outlet", type)) %>%
select(-toID) select(-toID)
outlets <- unique(outlets) outlets <- distinct(outlets)
agg_cats <- aggregate_catchments(flowpath = reconciled, agg_cats <- aggregate_catchments(flowpath = reconciled,
divide = divides, divide = divides,
outlets = outlets, outlets = outlets,
......
...@@ -1135,7 +1135,7 @@ wbin_POIcreation <- function(nhd, WBs_VPU, data_paths, crs, ...@@ -1135,7 +1135,7 @@ wbin_POIcreation <- function(nhd, WBs_VPU, data_paths, crs,
# Drive the inlet events # Drive the inlet events
nhd_inlet <- filter(nhd_WBs, !COMID %in% wb_outlet_events$COMID) nhd_inlet <- filter(nhd_WBs, !COMID %in% wb_outlet_events$COMID)
if(unique(nhd$VPUID) == "12"){ if("12" %in% unique(nhd$VPUID)){
nhd_inlet <- rbind(nhd_inlet, filter(nhd_WBs, COMID == 1304709)) nhd_inlet <- rbind(nhd_inlet, filter(nhd_WBs, COMID == 1304709))
} }
......
...@@ -27,8 +27,8 @@ fix_headwaters <- function(nhd_rds, out_gpkg, new_atts = NULL, ...@@ -27,8 +27,8 @@ fix_headwaters <- function(nhd_rds, out_gpkg, new_atts = NULL,
ble <- sf::st_zm(sf::st_as_sf(ble)) ble <- sf::st_zm(sf::st_as_sf(ble))
nhd <- sf::st_zm(nhd) nhd <- sf::st_zm(nhd)
sf::st_geometry(nhd)[!sf::st_is_empty(sf::st_geometry(ble)) & (nhd$StartFlag == 1 | nhd$Divergence == 2)] <- sf::st_geometry(nhd)[!sf::st_is_empty(sf::st_geometry(ble)) & (nhd$StartFlag == 1)] <-
sf::st_geometry(ble)[!sf::st_is_empty(sf::st_geometry(ble)) & (nhd$StartFlag == 1 | nhd$Divergence == 2)] sf::st_geometry(ble)[!sf::st_is_empty(sf::st_geometry(ble)) & (nhd$StartFlag == 1)]
if(!is.null(new_atts)) { if(!is.null(new_atts)) {
new_atts <- data.table::fread(new_atts, new_atts <- data.table::fread(new_atts,
...@@ -109,6 +109,12 @@ fix_headwaters <- function(nhd_rds, out_gpkg, new_atts = NULL, ...@@ -109,6 +109,12 @@ fix_headwaters <- function(nhd_rds, out_gpkg, new_atts = NULL,
nhd <- select(nhd, -override_tocomid) nhd <- select(nhd, -override_tocomid)
# remove remnant attributes
nhd <- select(nhd, -FromNode, -ToNode, -StartFlag -StreamCalc, -Divergence, -DnMinorHyd)
warning("naive duplication!")
nhd <- nhd[!duplicated(nhd$COMID), ]
sf::write_sf(nhd, out_gpkg, "reference_flowlines") sf::write_sf(nhd, out_gpkg, "reference_flowlines")
} }
......
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