Uses a cross section retrieval web services to retrieve a cross section between two endpoints.
get_xs_points(point1, point2, num_pts, res = 1)
sf data.frame containing points retrieved.
# \donttest{
point1 <- sf::st_sfc(sf::st_point(x = c(-105.9667, 36.17602)), crs = 4326)
point2 <- sf::st_sfc(sf::st_point(x = c(-105.97768, 36.17526)), crs = 4326)
(xs <- get_xs_points(point1, point2, 100))
#> https://labs-beta.waterdata.usgs.gov/api/nldi/pygeoapi/processes/nldi-xsatendpts/execution
#> {
#> "inputs": [
#> {
#> "id": "lat",
#> "type": "text/plain",
#> "value": [36.176, 36.1753]
#> },
#> {
#> "id": "lon",
#> "type": "text/plain",
#> "value": [-105.9667, -105.9777]
#> },
#> {
#> "id": "3dep_res",
#> "type": "text/plain",
#> "value": "1"
#> },
#> {
#> "id": "numpts",
#> "type": "text/plain",
#> "value": 100
#> }
#> ]
#> }
#> Simple feature collection with 101 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -105.9776 ymin: 36.17531 xmax: -105.9667 ymax: 36.176
#> Geodetic CRS: WGS 84
#> # A tibble: 101 × 5
#> id spatial_ref elevation_m distance_m geometry
#> <chr> <int> <dbl> <dbl> <POINT [°]>
#> 1 0 0 1779. 0 (-105.9667 36.176)
#> 2 1 0 1778. 9.74 (-105.9668 36.17599)
#> 3 2 0 1778. 19.5 (-105.9669 36.17599)
#> 4 3 0 1778. 29.2 (-105.967 36.17598)
#> 5 4 0 1776. 39.0 (-105.9671 36.17597)
#> 6 5 0 1776. 48.7 (-105.9672 36.17597)
#> 7 6 0 1776. 58.4 (-105.9674 36.17596)
#> 8 7 0 1775. 68.2 (-105.9675 36.17595)
#> 9 8 0 1775. 77.9 (-105.9676 36.17594)
#> 10 9 0 1774. 87.6 (-105.9677 36.17594)
#> # ℹ 91 more rows
if(inherits(xs, "sf")) {
bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005)
nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red")
plot(sf::st_transform(sf::st_sfc(point1, crs = 4326), 3857), add = TRUE)
plot(sf::st_transform(sf::st_sfc(point2, crs = 4326), 3857), add = TRUE)
plot(xs$distance_m, xs$elevation_m)
}
#> 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>36.1703069307237 -105.982591089109</gml:lowerCorner>
#> <gml:upperCorner>36.181 -105.9617</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
# }