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

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 = "sp",
  osrm.server = getOption("osrm.server"),
  osrm.profile = getOption("osrm.profile")
)

Arguments

loc

a SpatialPointsDataFrame or 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. If returnclass="sp" a SpatialLineDataFrame 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.

Value

A list of connected components. Each component contains:

trip

A SpatialLinesDataFrame or 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).

See Also

Examples

## Not run: 
# Load data
data("berlin")
library(sf)
# Get a trip with a set of points (sf POINT)
trips <- osrmTrip(loc = apotheke.sf, 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)

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