Uses a cross section retrieval web services to retrieve a cross section given a point and specified width. Orientation is determined based on direction of a the flowline found near point. This function uses a 10m National Elevation Dataset request on the back end.
get_xs_point(point, width, num_pts)
sf data.frame containing points retrieved.
# \donttest{
point <- sf::st_sfc(sf::st_point(x = c(-105.97218, 36.17592)), crs = 4326)
(xs <- get_xs_point(point, 300, 100))
#> https://labs-beta.waterdata.usgs.gov/api/nldi/pygeoapi/processes/nldi-xsatpoint/execution
#> {
#> "inputs": [
#> {
#> "id": "lat",
#> "type": "text/plain",
#> "value": 36.1759
#> },
#> {
#> "id": "lon",
#> "type": "text/plain",
#> "value": -105.9722
#> },
#> {
#> "id": "width",
#> "type": "text/plain",
#> "value": 300
#> },
#> {
#> "id": "numpts",
#> "type": "text/plain",
#> "value": 100
#> }
#> ]
#> }
#> Request failed [400]. Retrying in 1.8 seconds...
#> Request failed [400]. Retrying in 3.4 seconds...
#> Error calling processing service.
#> Original error:
#> Error in doTryCatch(return(expr), name, parentenv, handler): {
#> "type":"InvalidParameterValue",
#> "code":"InvalidParameterValue",
#> "description":"Error executing process: 'NoneType' object is not iterable"
#> }
#>
#> NULL
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(point, crs = 4326), 3857), add = TRUE)
plot(xs$distance_m, xs$elevation_m)
}
# }