diff --git a/DESCRIPTION b/DESCRIPTION index 5cadd44..af8414a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,7 @@ Description: Tools for using the 'StreamCat' and 'LakeCat' API and Depends: R (>= 4.1.0) Imports: sf, - nhdplusTools, + hydrogeofetch, jsonlite, httr2, curl (>= 6.0.0), diff --git a/R/lc_get_comid.R b/R/lc_get_comid.R index c91331d..4d97cce 100644 --- a/R/lc_get_comid.R +++ b/R/lc_get_comid.R @@ -22,7 +22,7 @@ #' @param crsys The epsg code if using a raw data frame #' #' @param buffer The amount of buffer to use to extend search for a waterbody -#' (simply passed to nhdplusTools::get_waterbodies) +#' (simply passed to hydrogeofetch::get_waterbodies) #' #' @return A new sf data frame with a populated 'COMID' column #' @@ -56,9 +56,9 @@ lc_get_comid <- function(dd = NULL, xcoord = NULL, output <- do.call(rbind, lapply(1:nrow(dd), function(i){ if (is.null(buffer)){ - wb <- nhdplusTools::get_waterbodies(dd[i,]) + wb <- hydrogeofetch::get_waterbodies(dd[i,]) } else { - wb <- nhdplusTools::get_waterbodies(dd[i,], buffer=buffer) + wb <- hydrogeofetch::get_waterbodies(dd[i,], buffer=buffer) } if (!is.null(wb)){ comid <- wb |> diff --git a/R/sc_get_comid.R b/R/sc_get_comid.R index 0a22c9a..7b09759 100644 --- a/R/sc_get_comid.R +++ b/R/sc_get_comid.R @@ -57,7 +57,7 @@ sc_get_comid <- function(dd = NULL, xcoord = NULL, geom_col <- attr(dd, "sf_column") run_for <- 1:nrow(dd) output <- do.call(rbind, lapply(1:nrow(dd), function(i){ - comid <- nhdplusTools::discover_nhdplus_id(dd[i,c(geom_col)]) + comid <- hydrogeofetch::discover_nhdplus_id(dd[i,c(geom_col)]) if (length(comid)==0L) comid <- NA else comid <- comid return(comid) })) diff --git a/R/sc_get_data.R b/R/sc_get_data.R index 019e1ed..4b4f859 100644 --- a/R/sc_get_data.R +++ b/R/sc_get_data.R @@ -611,7 +611,7 @@ NULL } # Assert-style validator -# - online = TRUE (default): query NLDI (nhdplusTools::get_nldi_feature) to confirm existence. +# - online = TRUE (default): query NLDI (hydrogeofetch::get_nldi_feature) to confirm existence. # - online = FALSE: validate against a local .valid_comids vector (must be available). # - Also errors if an ID is present (valid) but listed in .missing_COMIDs/.missing_comids. is_valid_comid <- function(comid, online = TRUE) { @@ -633,10 +633,6 @@ is_valid_comid <- function(comid, online = TRUE) { expected_missing <- unique(suppressWarnings(as.integer(expected_missing))) if (isTRUE(online)) { - if (!requireNamespace("nhdplusTools", quietly = TRUE)) { - stop("Online validation requires nhdplusTools. Install it or call assert_valid_comids(..., online = FALSE).", call. = FALSE) - } - # Query NLDI only for unique, numeric-looking IDs query_ids <- unique(ids_chr[!not_numeric]) exists_map <- setNames(logical(length(query_ids)), query_ids) @@ -645,7 +641,7 @@ is_valid_comid <- function(comid, online = TRUE) { query_ids, function(i) { out <- tryCatch( - nhdplusTools::get_nldi_feature(list(featureSource = "comid", featureID = i)), + hydrogeofetch::get_nldi_feature(list(featureSource = "comid", featureID = i)), error = function(e) NULL ) isTRUE(inherits(out, "sf")) && nrow(out) > 0 diff --git a/R/sc_plot.R b/R/sc_plot.R index 5713f74..9809e2f 100644 --- a/R/sc_plot.R +++ b/R/sc_plot.R @@ -205,7 +205,7 @@ sc_plotnni <- function(comid, include.nue = FALSE, include.inset = TRUE){ #comid comidint <- as.integer(comid) - flowline <- nhdplusTools::get_nhdplus(comid = comidint, realization = "flowline") + flowline <- hydrogeofetch::get_nhdplus(comid = comidint, realization = "flowline") point <- flowline |> sf::st_geometry() |> sf::st_centroid() |> diff --git a/vignettes/Articles/Applications.Rmd b/vignettes/Articles/Applications.Rmd index 4386224..27c0f0b 100644 --- a/vignettes/Articles/Applications.Rmd +++ b/vignettes/Articles/Applications.Rmd @@ -27,13 +27,13 @@ knitr::opts_chunk$set( ``` ### Plotting watershed data -In this example we access a single variable for the Calapooia River using `sc_get_data` function. We then use the `nhdplusTools` library to grab flowlines and watershed for the Calapooia, plot the selected StreamCat metric for the Calapooia River and show the watershed. +In this example we access a single variable for the Calapooia River using `sc_get_data` function. We then use the `hydrogeofetch` library to grab flowlines and watershed for the Calapooia, plot the selected StreamCat metric for the Calapooia River and show the watershed. ```{r wshd, results='hide'} library(StreamCatTools) start_comid = 23763517 nldi_feature <- list(featureSource = "comid", featureID = start_comid) -flowline_nldi <- nhdplusTools::navigate_nldi(nldi_feature, mode = "UT", data_source = "flowlines", distance=5000) +flowline_nldi <- hydrogeofetch::navigate_nldi(nldi_feature, mode = "UT", data_source = "flowlines", distance=5000) # get StreamCat metrics df <- sc_get_data(metric='pctimp2011', aoi='cat', comid=flowline_nldi$UT_flowlines$nhdplus_comid) @@ -45,7 +45,7 @@ df <- sc_get_data(metric='pctimp2011', aoi='cat', comid=flowline_nldi$UT_flowlin flowline_nldi <- flowline_nldi$UT_flowlines flowline_nldi$PCTIMP2011CAT <- df$pctimp2011cat[match(flowline_nldi$nhdplus_comid, df$comid)] -basin <- nhdplusTools::get_nldi_basin(nldi_feature = nldi_feature) +basin <- hydrogeofetch::get_nldi_basin(nldi_feature = nldi_feature) ``` ```{r wshd pt2} @@ -64,7 +64,7 @@ dplyr::glimpse(nrsa) # Promote data frame to sf spatial points data frame nrsa_sf <- sf::st_as_sf(nrsa, coords = c("LON_DD83", "LAT_DD83"), crs = 4269) -# Get COMIDs using nhdplusTools package +# Get COMIDs using hydrogeofetch package # nrsa$COMID<- NA # for (i in 1:nrow(nrsa_sf)){ # print (i) diff --git a/vignettes/Articles/LakeCat.Rmd b/vignettes/Articles/LakeCat.Rmd index bd6978e..f6dd4c0 100644 --- a/vignettes/Articles/LakeCat.Rmd +++ b/vignettes/Articles/LakeCat.Rmd @@ -76,7 +76,7 @@ head(metrics) ``` ## Get Waterbody COMIDs -In this example we use the `lc_get_comid` function to find COMIDs for a set of example lake locations we load into R.`lc_get_comid` is just a simple wrapper for `get_waterbodies` in the [hydrogeofetch](https://doi-usgs.github.io/nhdplusTools/) R package. We can then use the COMIDs we derive for our lake locations to get LakeCat metrics for these lakes as we show in after this. +In this example we use the `lc_get_comid` function to find COMIDs for a set of example lake locations we load into R.`lc_get_comid` is just a simple wrapper for `get_waterbodies` in the [hydrogeofetch](https://doi-usgs.github.io/hydrogeofetch/) R package. We can then use the COMIDs we derive for our lake locations to get LakeCat metrics for these lakes as we show in after this. ```{r comids, warning=FALSE, message=FALSE} dd <- data.frame(x = c(-89.198,-114.125,-122.044), y = c(45.502,47.877,43.730)) |> diff --git a/vignettes/Articles/NNI.Rmd b/vignettes/Articles/NNI.Rmd index 6dc57f4..23d5b77 100644 --- a/vignettes/Articles/NNI.Rmd +++ b/vignettes/Articles/NNI.Rmd @@ -188,12 +188,12 @@ tibble::tibble(sc_get_nni(year='2017', comid=com, aoi='cat,ws')) ## Plot a single NNI metric for a given watershed -In this example we access a single National Nutrient Inventory (NNI) metric for the Calapooia River basin using the `sc_get_data` function. We use the `nhdplusTools` library to pull in flowlines and the watershed boundary for the Calapooia River basin, plot the selected NNI metric for the Calapooia River and show the watershed. +In this example we access a single National Nutrient Inventory (NNI) metric for the Calapooia River basin using the `sc_get_data` function. We use the `hydrogeofetch` library to pull in flowlines and the watershed boundary for the Calapooia River basin, plot the selected NNI metric for the Calapooia River and show the watershed. ```{r farmn, results='hide'} start_comid = 23763517 nldi_feature <- list(featureSource = "comid", featureID = start_comid) -flowline_nldi <- nhdplusTools::navigate_nldi(nldi_feature, mode = "UT", data_source = "flowlines", distance=5000) +flowline_nldi <- hydrogeofetch::navigate_nldi(nldi_feature, mode = "UT", data_source = "flowlines", distance=5000) # get StreamCat metrics comids <- paste(as.integer(flowline_nldi$UT_flowlines$nhdplus_comid), collapse=",",sep="") @@ -203,7 +203,7 @@ df <- sc_get_data(metric='n_ff_2016', aoi='cat', comid=comids, showAreaSqKm=TRUE flowline_nldi <- flowline_nldi$UT_flowlines flowline_nldi$Farm_Nitrogon_2016 <- df$n_ff_2016cat[match(flowline_nldi$nhdplus_comid, df$comid)] -basin <- nhdplusTools::get_nldi_basin(nldi_feature = nldi_feature) +basin <- hydrogeofetch::get_nldi_basin(nldi_feature = nldi_feature) ``` ## Map the Results