Skip to content

Commit 184cea8

Browse files
committed
refinements for v2.2
1 parent 69bde0d commit 184cea8

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

R/hydrofabric_io.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ read_hydrofabric = function(gpkg = NULL,
154154

155155
write_hydrofabric = function(network_list,
156156
outfile,
157-
verbose = TRUE, enforce_dm = TRUE){
157+
verbose = TRUE,
158+
enforce_dm = TRUE){
158159

159160
hyaggregate_log("SUCCESS", glue("Writing {length(network_list)} layers to {outfile}"), verbose)
160161

R/nexus_topology.R

+13-9
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ realign_topology = function(network_list,
423423
#' @export
424424

425425
apply_nexus_topology = function(gpkg,
426-
vpu = NULL,
426+
vpu = NA,
427427
nexus_prefix = "nex-",
428428
terminal_nexus_prefix = "tnx-",
429429
coastal_nexus_prefix = "cnx-",
@@ -454,9 +454,12 @@ apply_nexus_topology = function(gpkg,
454454
term_add = term_filter
455455
}
456456

457-
if(!is.null(vpu)) { ngen_flows$topo$vpu = as.character(vpu) }
457+
ngen_flows$topo$vpuid = as.character(vpu)
458+
459+
ngen_flows$nexus$vpuid = as.character(vpu)
458460

459461
ngen_flows$flowpaths = ngen_flows$flowpaths %>%
462+
mutate(vpuid = as.character(vpu)) |>
460463
select(id, toid,
461464
mainstem, order, hydroseq,
462465
lengthkm, areasqkm, tot_drainage_areasqkm,
@@ -465,6 +468,7 @@ apply_nexus_topology = function(gpkg,
465468
contains("vpu"))
466469

467470
ngen_flows$divides = ngen_flows$divides %>%
471+
mutate(vpuid = as.character(vpu)) |>
468472
select(divide_id, toid, type, ds_id, areasqkm, contains("vpu")) %>%
469473
left_join(st_drop_geometry(select(ngen_flows$flowpaths, id, divide_id, lengthkm, tot_drainage_areasqkm )), by = "divide_id") %>%
470474
mutate(areasqkm = add_areasqkm(.),
@@ -493,12 +497,12 @@ apply_nexus_topology = function(gpkg,
493497
internal_nexus_prefix = internal_nexus_prefix) %>%
494498
full_join(st_drop_geometry(select(ngen_flows$flowpaths,
495499
has_divide,
496-
id, divide_id,
500+
id,
501+
divide_id,
497502
lengthkm,
498503
tot_drainage_areasqkm,
499504
mainstem,
500-
has_divide,
501-
contains("vpu"))),
505+
has_divide)),
502506
by = "id",
503507
multiple = "all") %>%
504508
full_join(st_drop_geometry(select(ngen_flows$divides, divide_id, areasqkm, n2 = type)), by = "divide_id") %>%
@@ -528,16 +532,16 @@ apply_nexus_topology = function(gpkg,
528532
filter(complete.cases(.)) %>%
529533
left_join(select(st_drop_geometry(ngen_flows$divides), divide_id, toid), by = 'divide_id') %>%
530534
left_join(select(tmp, -id), by = 'divide_id') %>%
531-
mutate(vpu = as.character(vpu),
535+
mutate(vpuid = as.character(vpu),
532536
poi_id = as.integer(poi_id))
533537

534538

535539
ngen_flows$network = filter(network, !type %in% c(c('coastal', "internal"))) %>%
536-
left_join(select(tmp,id, hf_source, hf_id, hf_id_part, hydroseq), by = 'id', relationship = "many-to-many") %>%
540+
left_join(select(tmp, id, hf_source, hf_id, hf_id_part, hydroseq), by = 'id', relationship = "many-to-many") %>%
537541
bind_rows(sinks) %>%
538-
select(id, toid, divide_id, ds_id, mainstem, poi_id, hydroseq, poi_id, #hl_uri,
542+
select(id, toid, divide_id, ds_id, mainstem, poi_id, hydroseq, #hl_uri,
539543
hf_source, hf_id, lengthkm, areasqkm, tot_drainage_areasqkm,
540-
type, vpu)
544+
type, vpuid)
541545
}
542546

543547
# if(layer_exists(gpkg, "hydrolocations")){

0 commit comments

Comments
 (0)