Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions R/lc_get_comid.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down Expand Up @@ -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 |>
Expand Down
2 changes: 1 addition & 1 deletion R/sc_get_comid.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
Expand Down
8 changes: 2 additions & 6 deletions R/sc_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/sc_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() |>
Expand Down
8 changes: 4 additions & 4 deletions vignettes/Articles/Applications.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/Articles/LakeCat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)) |>
Expand Down
6 changes: 3 additions & 3 deletions vignettes/Articles/NNI.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand All @@ -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
Expand Down
Loading