vl_elevation | R Documentation |
Build and send a Valhalla API query to get the elevation at a
set of input locations.
This function interfaces with the height service.
If sampling_dist
is provided, the elevation is sampled at regular
intervals along the input locations.
vl_elevation(loc, sampling_dist, server = getOption("valh.server"))
loc |
one (or multiples) point(s) at which to get elevation.
|
sampling_dist |
distance between each point to sample the elevation (in meters). Default is no sampling. |
server |
URL of the Valhalla server. |
An sf POINT object is returned with the following fields: 'distance' (the distance from the first points), 'height' (the sampled height on the DEM) and 'geometry' (the geometry of the sampled point).
## Not run:
# Inputs are data frames
apotheke.df <- read.csv(system.file("csv/apotheke.csv", package = "valh"))
# The first 5 points
pts <- apotheke.df[1:5, c("lon", "lat")]
# Ask for the elevation at these points
elev1 <- vl_elevation(loc = pts)
# Inputs are sf points
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "valh"),
quiet = TRUE
)
# The first 5 points
pts2 <- apotheke.sf[1:5, ]
# Ask for the elevation at these points
elev2 <- vl_elevation(loc = pts2)
# Ask for elevation between the first and the second points,
# sampling every 100 meters
elev3 <- vl_elevation(loc = apotheke.sf[1:2, ], sampling_dist = 100)
# Plot the corresponding elevation profile
plot(as.matrix(st_drop_geometry(elev3)), type = "l")
# Input is a route (sf LINESTRING) from vl_route
# Compute the route between the first and the second points
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "valh"),
quiet = TRUE
)
src <- apotheke.sf[1, ]
dst <- apotheke.sf[2, ]
route <- vl_route(src = src, dst = dst)
# Split the LINESTRING into its composing points
pts_route <- sf::st_cast(route, "POINT")
# Ask for the elevation at these points
elev4 <- vl_elevation(loc = pts_route)
# Plot the elevation profile
plot(as.matrix(st_drop_geometry(elev4)), type = "l")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.