From 57fc69aae914aa9ab34401592e01ce42c5ca501d Mon Sep 17 00:00:00 2001 From: David Blodgett Date: Tue, 8 Sep 2026 12:51:22 -0500 Subject: [PATCH] migrate nhdplusTools to hydrogeofetch --- DESCRIPTION | 2 +- R/lc_get_comid.R | 6 +++--- R/sc_get_comid.R | 2 +- R/sc_plot.R | 2 +- man/lc_get_comid.Rd | 2 +- vignettes/Articles/Applications.Rmd | 8 ++++---- vignettes/Articles/LakeCat.Rmd | 6 +++--- vignettes/Articles/NNI.Rmd | 6 +++--- 8 files changed, 17 insertions(+), 17 deletions(-) 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_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/man/lc_get_comid.Rd b/man/lc_get_comid.Rd index d56c481..9d56cd7 100644 --- a/man/lc_get_comid.Rd +++ b/man/lc_get_comid.Rd @@ -26,7 +26,7 @@ frame} \item{crsys}{The epsg code if using a raw data frame} \item{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)} } \value{ A new sf data frame with a populated 'COMID' column 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 c095174..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 [nhdplusTools](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)) |> @@ -117,10 +117,10 @@ knitr::kable(df) ## Get lake and lake watersheds as `sf` objects -`StreamCatTools` includes a function `lc_get_watershed` that will return the watershed of any lake by COMID from an AWS S3 bucket of partitioned geoparquet files for all LakeCat lake watersheds (both on-network and off-network lakes). The watershed requested is returned as an `sf` object and uses `duckDB` as well as optional parallelization for faster data returns and specification of a specific HUC2 if known to reduce search time. **NOTE** `lc_get_watershed` currently only returns one watershed per request. This can be used in conjunction with `nhdplusTools` function `get_waterbodies` to map lake features for which `LakeCat` metrics are requested as shown below. +`StreamCatTools` includes a function `lc_get_watershed` that will return the watershed of any lake by COMID from an AWS S3 bucket of partitioned geoparquet files for all LakeCat lake watersheds (both on-network and off-network lakes). The watershed requested is returned as an `sf` object and uses `duckDB` as well as optional parallelization for faster data returns and specification of a specific HUC2 if known to reduce search time. **NOTE** `lc_get_watershed` currently only returns one watershed per request. This can be used in conjunction with `hydrogeofetch` function `get_waterbodies` to map lake features for which `LakeCat` metrics are requested as shown below. ```{r get_lake} -lake <- nhdplusTools::get_waterbodies(id = 19334077) +lake <- hydrogeofetch::get_waterbodies(id = 19334077) ``` ```{r get_watershed} 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