vl_matrix | R Documentation |
Build and send Valhalla API queries to get travel time matrices
between points.
This function interfaces the matrix Valhalla service.
Use src
and dst
to set different origins and destinations.
Use loc
to compute travel times or travel distances between all
points.
vl_matrix(
src,
dst,
loc,
costing = "auto",
costing_options = list(),
server = getOption("valh.server")
)
src |
origin points.
If relevant, row names are used as identifiers. |
dst |
destination.
If relevant, row names are used as identifiers. |
loc |
points.
If relevant, row names are used as identifiers. |
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. |
The output of this function is a list composed of one or two matrices and 2 data.frames
durations: a matrix of travel times (in minutes)
distances: a matrix of distances (in specified units, default to kilometers)
sources: a data.frame of the coordinates of the points actually used as starting points (EPSG:4326 - WGS84)
destinations: a data.frame of the coordinates of the points actually used as destinations (EPSG:4326 - WGS84)
## Not run:
# Inputs are data frames
apotheke.df <- read.csv(system.file("csv/apotheke.csv", package = "valh"))
# Travel time matrix
distA <- vl_matrix(loc = apotheke.df[1:50, c("lon", "lat")])
# First 5 rows and columns
distA$durations[1:5, 1:5]
# Travel time matrix with different sets of origins and destinations
distA2 <- vl_matrix(
src = apotheke.df[1:10, c("lon", "lat")],
dst = apotheke.df[11:20, c("lon", "lat")]
)
# First 5 rows and columns
distA2$durations[1:5, 1:5]
# Inputs are sf points
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "valh"),
quiet = TRUE
)
distA3 <- vl_matrix(loc = apotheke.sf[1:10, ])
# First 5 rows and columns
distA3$durations[1:5, 1:5]
# Travel time matrix with different sets of origins and destinations
distA4 <- vl_matrix(src = apotheke.sf[1:10, ], dst = apotheke.sf[11:20, ])
# First 5 rows and columns
distA4$durations[1:5, 1:5]
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.