osrmTable | R Documentation |
Build and send OSRM API queries to get travel time matrices
between points. This function interfaces the table OSRM service.
Use src
and dst
to set different origins and destinations.
Use loc
to compute travel times or travel distances between all
points.
osrmTable(
src,
dst = src,
loc,
exclude,
measure = "duration",
osrm.server = getOption("osrm.server"),
osrm.profile = getOption("osrm.profile")
)
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. |
exclude |
pass an optional "exclude" request option to the OSRM API (not allowed with the OSRM demo server). |
measure |
a character indicating what measures are calculated. It can be "duration" (in minutes), "distance" (meters), or both c('duration', 'distance'). |
osrm.server |
the base URL of the routing server. |
osrm.profile |
the routing profile to use, e.g. "car", "bike" or "foot". |
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 meters)
sources: a data.frame of the coordinates of the points actually used as starting points (EPSG:4326 - WGS84)
sources: a data.frame of the coordinates of the points actually used as destinations (EPSG:4326 - WGS84)
The OSRM demo server does not allow large queries (more than 10000 distances
or durations).
If you use your own server and if you want to get a large number of distances
make sure to set the "max-table-size" option (Max. locations supported in
table) of the OSRM server accordingly.
## Not run:
# Inputs are data frames
apotheke.df <- read.csv(system.file("csv/apotheke.csv", package = "osrm"))
# Travel time matrix
distA <- osrmTable(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 <- osrmTable(
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 = "osrm"),
quiet = TRUE
)
distA3 <- osrmTable(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 <- osrmTable(src = apotheke.sf[1:10, ], dst = apotheke.sf[11:20, ])
# First 5 rows and columns
distA4$durations[1:5, 1:5]
# Road distance matrix with different sets of origins and destinations
distA5 <- osrmTable(
src = apotheke.sf[1:10, ], dst = apotheke.sf[11:20, ],
measure = "distance"
)
# First 5 rows and columns
distA5$distances[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.