Skip to content
Snippets Groups Projects
Commit f00bc746 authored by Blodgett, David L.'s avatar Blodgett, David L.
Browse files

improve headwater handling

parent 023afaf3
No related branches found
No related tags found
No related merge requests found
...@@ -100,13 +100,26 @@ get_hr_pairs <- function(nhdhr_path, nhdplus_hw_outlets, prj, cores = 5, max_str ...@@ -100,13 +100,26 @@ get_hr_pairs <- function(nhdhr_path, nhdplus_hw_outlets, prj, cores = 5, max_str
dplyr::bind_rows(hr_pairs) dplyr::bind_rows(hr_pairs)
} }
#' add 24k headwater pairs
#' @param hr_pairs id COMID pairs from catchment-based headwater matching
#' @param extra_file character path to file containing previously matched headwaters
#'
add_24k_pairs <- function(hr_pairs, extra_file) { add_24k_pairs <- function(hr_pairs, extra_file) {
found <- readr::read_csv(extra_file, col_types = "ccncc") found <- readr::read_csv(extra_file, col_types = "ccncc")
found <- found[!found$hr_id %in% hr_pairs$id,] # where a mainstem is in the 24k headwaters but not hr
found_new <- found[!found$COMID %in% hr_pairs$COMID,]
bind_rows(select(found, COMID, id = hr_id), # where the 24k headwaters are different
found_diff <- inner_join(select(found, COMID, hr_id), hr_pairs, by = "COMID") |>
filter(hr_id != id)
# remove where things are different
hr_pairs <- filter(hr_pairs, !COMID %in% found_diff$COMID)
bind_rows(select(found_new, COMID, id = hr_id),
select(found_diff, COMID, id = hr_id),
select(hr_pairs, COMID, id)) select(hr_pairs, COMID, id))
} }
......
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