Learn R Programming

osrm (version 3.3.1)

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")

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".

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).

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.

See Also

osrmIsochrone

Examples

Run this code
# 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]
# }

Run the code above in your browser using DataLab