View source: R/vl_optimized_route.R
vl_optimized_route | R Documentation |
Build and send a Valhalla API query to get the optimized route
(and so a solution to the Traveling Salesman Problem) between multiple points.
This function interfaces with the optimized_route Valhalla service.
vl_optimized_route(
loc,
end_at_start = FALSE,
costing = "auto",
costing_options = list(),
server = getOption("valh.server")
)
loc |
starting point and waypoints to reach along the
route.
The first row or element is the starting point. |
end_at_start |
logical indicating whether the route should end at the first point (making the trip a loop). |
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. |
a list of two elements:
summary: a list whose elements are a summary of the trip (duration, distance, presence of tolls, highways, time restrictions and ferries),
shape: an sf LINESTRING of the optimized route.
## Not run:
# Inputs are data frames
apotheke.df <- read.csv(system.file("csv/apotheke.csv", package = "valh"))
pts1 <- apotheke.df[1:6, c("lon", "lat")]
# Compute the optimized route between the first 6 points
# (starting point, 4 waypoints and final destination), by bike
trip1a <- vl_optimized_route(loc = pts1, end_at_start = FALSE, costing = "bicycle")
# Compute the optimized route between the first 6 points returning to the
# starting point, by bike
trip1b <- vl_optimized_route(loc = pts1, end_at_start = TRUE, costing = "bicycle")
# Inputs are sf points
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "valh"),
quiet = TRUE
)
pts2 <- apotheke.sf[1:6, ]
# Compute the optimized route between the first 6 points
# (starting point, 4 waypoints and final destination)
trip2a <- vl_optimized_route(loc = pts2, end_at_start = FALSE, costing = "auto")
# Compute the optimized route between the first 6 points, returning to the
# starting point
trip2b <- vl_optimized_route(loc = pts2, end_at_start = TRUE, costing = "auto")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.