Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

osrmTable

Get Travel Time Matrices Between Points


Description

Build and send OSRM API queries to get travel time matrices between points. This function interfaces the table OSRM service.

Usage

osrmTable(
  loc,
  src = NULL,
  dst = NULL,
  exclude = NULL,
  gepaf = FALSE,
  measure = "duration",
  osrm.server = getOption("osrm.server"),
  osrm.profile = getOption("osrm.profile")
)

Arguments

loc

a data frame containing 3 fields: points identifiers, longitudes and latitudes (WGS84). It can also be a SpatialPointsDataFrame, a SpatialPolygonsDataFrame or an sf object. If so, row names are used as identifiers. If loc parameter is used, all pair-wise distances are computed.

src

a data frame containing origin points identifiers, longitudes and latitudes (WGS84). It can also be a SpatialPointsDataFrame, a SpatialPolygonsDataFrame or an sf object. If so, row names are used as identifiers. If dst and src parameters are used, only pairs between scr/dst are computed.

dst

a data frame containing destination points identifiers, longitudes and latitudes (WGS84). It can also be a SpatialPointsDataFrame a SpatialPolygonsDataFrame or an sf object. If so, row names are used as identifiers.

exclude

pass an optional "exclude" request option to the OSRM API.

gepaf

a boolean indicating if coordinates are sent encoded with the google encoded algorithm format (TRUE) or not (FALSE). Must be FALSE if using the public OSRM API.

measure

a character indicating what measures are calculated. It can be "duration" (in minutes), "distance" (meters), or both c('duration', 'distance'). The demo server only allows "duration".

osrm.server

the base URL of the routing server. getOption("osrm.server") by default.

osrm.profile

the routing profile to use, e.g. "car", "bike" or "foot" (when using the routing.openstreetmap.de test server). getOption("osrm.profile") by default.

Details

If loc, src or dst are data frames we assume that the 3 first columns of the data frame are: identifiers, longitudes and latitudes.

Value

A list containing 3 data frames is returned. durations is the matrix of travel times (in minutes), sources and destinations are the coordinates of the origin and destination points actually used to compute the travel times (WGS84).

Note

If you want to get a large number of distances make sure to set the "max-table-size" argument (Max. locations supported in table) of the OSRM server accordingly.

See Also

Examples

## Not run: 
# Load data
data("berlin")

# Inputs are data frames
# Travel time matrix
distA <- osrmTable(loc = apotheke.df[1:50, c("id","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("id","lon","lat")],
                    dst = apotheke.df[11:20,c("id","lon","lat")])
# First 5 rows and columns
distA2$durations[1:5,1:5]

# Inputs are sf points
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]

## End(Not run)

osrm

Interface Between R and the OpenStreetMap-Based Routing Service OSRM

v3.4.1
GPL-3
Authors
Timothée Giraud [cre, aut] (<https://orcid.org/0000-0002-1932-3323>), Robin Cura [ctb], Matthieu Viry [ctb], Robin Lovelace [ctb] (<https://orcid.org/0000-0001-5679-6536>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.