Learn R Programming

stplanr (version 0.1.0)

viaroute: Query OSRM service and return json string result

Description

Query OSRM service and return json string result

Usage

viaroute(startlat = NULL, startlng = NULL, endlat = NULL, endlng = NULL,
  viapoints = NULL, osrmurl = "http://router.project-osrm.org", zoom = 18,
  instructions = TRUE, alt = TRUE, geometry = TRUE, uturns = TRUE)

Arguments

startlat
A single value or vector containing latitude(s) of the start of routes.
startlng
A single value or vector containing longitude(s) of the end of routes.
endlat
A single value or vector containing latitude(s) of the end of routes.
endlng
A single value or vector containing longitude(s) of the end of routes.
viapoints
A list of dataframes containing latitude (first column), longitude (second) column for points to use for each route. Optionally a third column containing a boolean value indicating if u-turns are allowed at each viapoint.
osrmurl
URL for OSRM sservice, e.g. an osrm instance running on localhost. By default this is "http://router.project-osrm.org".
zoom
Zoom level for route geometry (0 to 18) (default = 18). Higher values are more detailed.
instructions
Boolean value to return instructions (default = TRUE).
alt
Boolean value to return alternative routes (default = TRUE).
geometry
Boolean value to return route geometries (default = TRUE).
uturns
Boolean value to allow uturns at via points (default = TRUE).

Details

Constructs the query URL used with the OSRM HTTP API and returns a string or vector of strings with the json-encoded results. Can be used in conjunction with the viaroute2sldf function.

Examples

Run this code
exroutes <- viaroute(50, 0, 51, 1)
  r1 <- viaroute2sldf(exroutes)
  exroutes <- viaroute(50, 0, 51, 1, zoom = 4)
  r2 <- viaroute2sldf(exroutes)
  # Requires mapview to be installed
  # Show the difference between outputs with different zoom levels
  mapview::mapview(r1) +
   mapview::mapview(r2, color = "blue")
  exroutes <- viaroute(viapoints=list(data.frame(x=c(-33.5,-33.6,-33.7),y=c(150,150.1,150.2))))
  r <- viaroute2sldf(exroutes)
  plot(r)

Run the code above in your browser using DataLab