Uses a cross section retrieval web services to retrieve elevation along a path.

get_elev_along_path(points, num_pts, res = 1, status = TRUE)

Arguments

points

sf data.frame containing a point column.

num_pts

numeric number of points to retrieve along the cross section.

res

integer resolution of 3D Elevation Program data to request. Must be one of: 1, 3, 5, 10, 30, 60.

status

logical

Value

sf data.frame containing points retrieved. Names include "id", "distance_m", "elevation_m", "spatial_ref", "geometry", and ".group". .group tracks which input point each set of output points belongs to.

Examples

# \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)
point3 <- sf::st_sfc(sf::st_point(x = c(-105.98869, 36.17450)), crs = 4326)

points <- sf::st_as_sf(c(point1, point2, point3))

(xs <- get_elev_along_path(points, 100))
#> Requestion segment 1 of 2
#> POST https://api.water.usgs.gov/nldi/pygeoapi/processes/nldi-xsatendpts/execution
#> {
#>   "inputs": [
#>     {
#>       "id": "lat",
#>       "type": "text/plain",
#>       "value": ["36.17602", "36.17526"]
#>     },
#>     {
#>       "id": "lon",
#>       "type": "text/plain",
#>       "value": ["-105.9667", "-105.97768"]
#>     },
#>     {
#>       "id": "3dep_res",
#>       "type": "text/plain",
#>       "value": "1"
#>     },
#>     {
#>       "id": "numpts",
#>       "type": "text/plain",
#>       "value": "100"
#>     }
#>   ]
#> }
#> Requestion segment 2 of 2
#> POST https://api.water.usgs.gov/nldi/pygeoapi/processes/nldi-xsatendpts/execution
#> {
#>   "inputs": [
#>     {
#>       "id": "lat",
#>       "type": "text/plain",
#>       "value": ["36.17526", "36.1745"]
#>     },
#>     {
#>       "id": "lon",
#>       "type": "text/plain",
#>       "value": ["-105.97768", "-105.98869"]
#>     },
#>     {
#>       "id": "3dep_res",
#>       "type": "text/plain",
#>       "value": "1"
#>     },
#>     {
#>       "id": "numpts",
#>       "type": "text/plain",
#>       "value": "100"
#>     }
#>   ]
#> }
#> Simple feature collection with 202 features and 5 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -105.9886 ymin: 36.17451 xmax: -105.9667 ymax: 36.17602
#> Geodetic CRS:  WGS 84
#> # A tibble: 202 × 6
#>    id    spatial_ref elevation_m distance_m             geometry .group
#>  * <chr>       <int>       <dbl>      <dbl>          <POINT [°]>  <int>
#>  1 0               0       1779.       0    (-105.9667 36.17602)      1
#>  2 1               0       1779.       9.73 (-105.9668 36.17601)      1
#>  3 2               0       1779.      19.5    (-105.9669 36.176)      1
#>  4 3               0       1778.      29.2     (-105.967 36.176)      1
#>  5 4               0       1776.      38.9  (-105.9671 36.17599)      1
#>  6 5               0       1776.      48.6  (-105.9672 36.17598)      1
#>  7 6               0       1776.      58.4  (-105.9674 36.17597)      1
#>  8 7               0       1776.      68.1  (-105.9675 36.17597)      1
#>  9 8               0       1775.      77.8  (-105.9676 36.17596)      1
#> 10 9               0       1775.      87.5  (-105.9677 36.17595)      1
#> # ℹ 192 more rows

if(inherits(xs, "sf")) {

bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005)

hydrogeofetch::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(sf::st_transform(sf::st_sfc(point3, crs = 4326), 3857), add = TRUE)

plot(xs$distance_m, xs$elevation_m)
}
#> GET https://api.water.usgs.gov/fabric/pygeoapi/collections/nhdflowline_network/items?bbox=-105.993580990099,36.1695075247886,-105.9617,36.18102&limit=500&offset=0



# }