Uses a raindrop trace web service to trace the nhdplus digital elevation model to the nearest downslope flowline.
get_raindrop_trace(point, direction = "down")
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))
#> https://labs-beta.waterdata.usgs.gov/api/nldi/pygeoapi/processes/nldi-flowtrace/execution
#> {
#> "inputs": [
#> {
#> "id": "lat",
#> "type": "text/plain",
#> "value": "42.9561"
#> },
#> {
#> "id": "lon",
#> "type": "text/plain",
#> "value": "-89.2158"
#> },
#> {
#> "id": "raindroptrace",
#> "type": "text/plain",
#> "value": "true"
#> },
#> {
#> "id": "direction",
#> "type": "text/plain",
#> "value": "down"
#> }
#> ]
#> }
#> Simple feature collection with 2 features and 7 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: -89.2158 ymin: 42.94986 xmax: -89.20944 ymax: 42.95673
#> 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… 267. 28.6 <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
#> https://api.water.usgs.gov/geoserver/wmadata/ows
#> <?xml version="1.0" encoding="UTF-8"?>
#> <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" service="WFS" version="1.1.0" outputFormat="application/json" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
#> <wfs:Query xmlns:feature="https://api.water.usgs.gov/wmadata" typeName="feature:nhdflowline_network" srsName="EPSG:4269">
#> <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
#> <ogc:And>
#> <ogc:BBOX>
#> <ogc:PropertyName>the_geom</ogc:PropertyName>
#> <gml:Envelope srsName="urn:x-ogc:def:crs:EPSG:4326">
#> <gml:lowerCorner>42.944857 -89.2208</gml:lowerCorner>
#> <gml:upperCorner>42.961727 -89.204436</gml:upperCorner>
#> </gml:Envelope>
#> </ogc:BBOX>
#> </ogc:And>
#> </ogc:Filter>
#> </wfs:Query>
#> </wfs:GetFeature>
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Spherical geometry (s2) switched on
#> Zoom set to: 12
# }