vl_route {valh} | R Documentation |
Get the Shortest Path Between Two Points
Description
Build and send a Valhalla API query to get the travel geometry
between two points.
This function interfaces with the route Valhalla service.
Use src
and dst
to get the shortest direct route between
two points. Use loc
to get the shortest route between two points using
ordered waypoints.
Usage
vl_route(
src,
dst,
loc,
costing = "auto",
costing_options = list(),
server = getOption("valh.server")
)
Arguments
src |
starting point of the route.
If relevant, row names are used as identifiers. |
dst |
destination of the route.
If relevant, row names are used as identifiers. |
loc |
starting point, waypoints (optional) and destination of the
route.
The first row or element is the starting point then waypoints are used in
the order they are stored in |
costing |
costing model to use. |
costing_options |
list of options to use with the costing model (see https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#costing-options for more details about the options available for each costing model). |
server |
URL of the Valhalla server. |
Value
The output of this function is an sf LINESTRING of the shortest route.
It contains 4 fields:
starting point identifier
destination identifier
travel time in minutes
travel distance in kilometers.
Examples
## Not run:
# Inputs are data frames
apotheke.df <- read.csv(system.file("csv/apotheke.csv", package = "valh"))
src <- apotheke.df[1, c("lon", "lat")]
dst <- apotheke.df[2, c("lon", "lat")]
# Route between the two points, using bicycle costing model
route1 <- vl_route(src = src, dst = dst, costing = "bicycle")
# Inputs are sf points
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "valh"),
quiet = TRUE
)
srcsf <- apotheke.sf[1, ]
dstsf <- apotheke.sf[2, ]
# Route between the two points, using bicycle costing model and a custom
# costing option
route2 <- vl_route(
src = srcsf,
dst = dstsf,
costing = "bicycle",
costing_options = list(cycling_speed = 19)
)
## End(Not run)