Uses a raindrop trace web service to trace the nhdplus digital elevation model to the nearest downslope flowline.
get_raindrop_trace(point, direction = "down")sfc POINT including crs as created by:
sf::st_sfc(sf::st_point(.. ,..), crs)
character "up", "down", or "none".
Controls the portion of the split flowline that is returned along with
the raindrop trace line.
sf data.frame containing raindrop trace and requested portion of flowline.
# \donttest{
point <- sf::st_sfc(sf::st_point(x = c(-89.2158, 42.9561)), crs = 4326)
(trace <- get_raindrop_trace(point))
#> Simple feature collection with 2 features and 7 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: -89.21572 ymin: 42.94986 xmax: -89.20944 ymax: 42.95699
#> Geodetic CRS: WGS 84
#> # A tibble: 2 × 8
#> id gnis_name comid reachcode raindrop_pathDist measure intersection_point
#> <chr> <chr> <int> <chr> <dbl> <dbl> <list>
#> 1 down… Yahara R… 1.33e7 07090002… 273. 29.7 <dbl [2]>
#> 2 rain… NA NA NA NA NA <dbl [0]>
#> # ℹ 1 more variable: geometry <LINESTRING [°]>
if(inherits(trace, "sf")) {
bbox <- sf::st_bbox(trace) + c(-0.005, -0.005, 0.005, 0.005)
nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE)
plot(sf::st_transform(sf::st_geometry(trace)[1], 3857), add = TRUE, col = "red")
plot(sf::st_transform(sf::st_geometry(trace)[2], 3857), add = TRUE, col = "black")
}
#> Spherical geometry (s2) switched off
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
#> Zoom set to: 12
# }