diff --git a/hyfabric/R/poi_creation.R b/hyfabric/R/poi_creation.R index 2cc96a0a5cc42864c0ed0a01e021e7d08b9d6a10..506d3e8dcd372d265ae84e9e9a4429b2076b2e07 100644 --- a/hyfabric/R/poi_creation.R +++ b/hyfabric/R/poi_creation.R @@ -19,22 +19,15 @@ POI_creation<-function(srcData, nhdDF, IDfield){ POIs <- sub_segs %>% get_node(., position = "end") %>% mutate(COMID = sub_segs$COMID) %>% - mutate(Type_HUC12 = NA, Type_WBIn = NA, Type_WBOut = NA, Type_Gages = NA, Type_TE = NA, Type_NID = NA, Type_Conf = NA, - Type_Term = NA, Type_Elev = NA, Type_Travel = NA) %>% inner_join(srcData %>% select(COMID, ID), by = "COMID") %>% - mutate(!!(paste0("Type_", IDfield)) := ID) - - if(!(paste0("Type_", IDfield)) %in% colnames(POIs)){ - POIs <- POIs %>% select(COMID, Type_HUC12, Type_Gages, Type_TE, Type_NID, Type_WBIn, Type_WBOut, Type_Conf, - Type_Term, Type_Elev, Type_Travel) - } else { - POIs <- POIs %>% select(COMID, Type_HUC12, Type_Gages, Type_TE, - Type_NID, Type_WBIn, Type_WBOut, Type_Conf, Type_Term, Type_Elev, Type_Travel, !!(paste0("Type_", IDfield))) - } + mutate(!!(paste0("Type_", IDfield)) := ID) %>% + select(COMID, !!(paste0("Type_", IDfield))) %>% + st_as_sf() return(POIs) } + #' Adds the type attribute for co-located POIs of multiple themes #' @param new_POIs (sf data.frame) new POIs to be tested against existing #' @param POIs (sf data.frame) Existing POIs @@ -87,12 +80,15 @@ addType <- function(new_POIs, POIs, IDfield, nexus = TRUE, bind = TRUE){ # Bind unless indicated not to if(bind){ - POIs_fin <- rbind(POIs_fin, filter(new_POIs, !COMID %in% POIs_fin$COMID)) + POIs_fin <- data.table::rbindlist(list(POIs_fin, filter(new_POIs, !COMID %in% POIs_fin$COMID)), + fill = TRUE) %>% + st_as_sf() } # Add nexus back in if excluded if(nexus){ - POIs_fin <- rbind(POIs_fin, nexus_POIs) + POIs_fin <- data.table::rbindlist(list(POIs_fin, nexus_POIs), fill = TRUE) %>% + st_as_sf() } return(POIs_fin)