Get a basin boundary for a given NLDI feature.

get_nldi_basin(nldi_feature, simplify = TRUE, split = FALSE)

Arguments

nldi_feature

list with names `featureSource` and `featureID` where `featureSource` is derived from the "source" column of the response of get_nldi_sources and the `featureID` is a known identifier from the specified `featureSource`.

simplify

logical should response geometry be simplified for visualization and performance?

split

logical should response resolve precisely to the location of the `nldi_feature`? Setting `TRUE` calls an additional service and will be slower and less robust.

Value

sf data.frame with result basin boundary

Details

Only resolves to the nearest NHDPlus catchment divide. See: https://waterdata.usgs.gov/blog/nldi-intro/ for more info on the nldi.

Examples

# \donttest{
library(sf)
library(dplyr)

nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-05428500")

site <- get_nldi_feature(nldi_nwis)

basin <- get_nldi_basin(nldi_feature = nldi_nwis)

plot(st_geometry(basin))


basin
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -89.60465 ymin: 43.03507 xmax: -89.20378 ymax: 43.36607
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 1
#>                                                                         geometry
#>                                                                    <POLYGON [°]>
#> 1 ((-89.35859 43.11776, -89.35423 43.11546, -89.35437 43.11067, -89.34997 43.10…

basin2 <- get_nldi_basin(nldi_feature = nldi_nwis,
                         simplify = FALSE, split = TRUE)

if(inherits(basin, "sf") & inherits(basin2, "sf")) {

length(st_coordinates(basin))
length(st_coordinates(basin2))

plot(st_geometry(st_buffer(site, units::set_units(3000, "m"))), border = NA)

plot(st_geometry(site), add = TRUE)
plot(st_geometry(basin2), add = TRUE)

plot(st_geometry(basin), border = "red", add = TRUE)

}

# }