Learn R Programming

osrm (version 3.5.1)

osrmTrip: Get the Travel Geometry Between Multiple Unordered Points

Description

Build and send an OSRM API query to get the shortest travel geometry between multiple points. This function interfaces the trip OSRM service.

Usage

osrmTrip(
  loc,
  exclude = NULL,
  overview = "simplified",
  returnclass = "sf",
  osrm.server = getOption("osrm.server"),
  osrm.profile = getOption("osrm.profile")
)

Value

A list of connected components. Each component contains:

trip

An sf LINESTRING (loc's CRS if there is one, WGS84 if not) containing a line for each step of the trip.

summary

A list with 2 components: duration (in minutes) and distance (in kilometers).

Arguments

loc

an sf object of the waypoints, or a data.frame with points as rows and 3 columns: identifier, longitudes and latitudes (WGS84 decimal degrees).

exclude

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

overview

"full", "simplified". Add geometry either full (detailed) or simplified according to highest zoom level it could be display on.

returnclass

if returnclass="sf" an sf LINESTRING is returned.

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

As stated in the OSRM API, if input coordinates can not be joined by a single trip (e.g. the coordinates are on several disconnecte islands) multiple trips for each connected component are returned.

See Also

osrmRoute

Examples

Run this code
if (FALSE) {
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "osrm"), 
                       quiet = TRUE)
# Get a trip with a set of points (sf POINT)
trips <- osrmTrip(loc = apotheke.sf[1:5, ], returnclass = "sf")
mytrip <- trips[[1]]$trip
# Display the trip
plot(st_geometry(mytrip), col = "black", lwd = 4)
plot(st_geometry(mytrip), col = c("red", "white"), lwd = 1, add = TRUE)
plot(st_geometry(apotheke.sf), pch = 21, bg = "red", cex = 1, add = TRUE)
}

Run the code above in your browser using DataLab