Get the Travel Geometry Between Multiple Unordered Points
Build and send an OSRM API query to get the shortest travel geometry between multiple points. This function interfaces the trip OSRM service.
osrmTrip( loc, exclude = NULL, overview = "simplified", returnclass = "sp", osrm.server = getOption("osrm.server"), osrm.profile = getOption("osrm.profile") )
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. |
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.
A list of connected components. Each component contains:
A SpatialLinesDataFrame or sf LINESTRING (loc's CRS if there is one, WGS84 if not) containing a line for each step of the trip.
A list with 2 components: duration (in minutes) and distance (in kilometers).
## 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)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.