Plan a single route with CycleStreets.net
Provides an R interface to the CycleStreets.net cycle planning API, a route planner made by cyclists for cyclists. The function returns a SpatialLinesDataFrame object representing the an estimate of the fastest, quietest or most balance route. Currently only works for the United Kingdom and part of continental Europe, though other areas may be requested by contacting CycleStreets. See https://www.cyclestreets.net/api/for more information.
route_cyclestreets( from, to, plan = "fastest", silent = TRUE, pat = NULL, base_url = "https://www.cyclestreets.net", reporterrors = TRUE, save_raw = "FALSE" )
from |
Text string or coordinates (a numeric vector of
|
to |
Text string or coordinates (a numeric vector of
|
plan |
Text strong of either "fastest" (default), "quietest" or "balanced" |
silent |
Logical (default is FALSE). TRUE hides request sent. |
pat |
The API key used. By default this is set to NULL and this is usually aquired automatically through a helper, api_pat(). |
base_url |
The base url from which to construct API requests (with default set to main server) |
reporterrors |
Boolean value (TRUE/FALSE) indicating if cyclestreets (TRUE by default). should report errors (FALSE by default). |
save_raw |
Boolean value which returns raw list from the json if TRUE (FALSE by default). |
This function uses the online routing service CycleStreets.net to find routes suitable for cyclists between origins and destinations. Requires an internet connection, a CycleStreets.net API key and origins and destinations within the UK (and various areas beyond) to run.
Note that if from
and to
are supplied as
character strings (instead of lon/lat pairs), Google's
geo-coding services are used via geo_code()
.
You need to have an api key for this code to run. Loading a locally saved copy of the api key text string before running the function, for example, will ensure it is available on any computer:
mytoken <- readLines("~/Dropbox/dotfiles/cyclestreets-api-key-rl") Sys.setenv(CYCLESTREETS = mytoken)
if you want the API key to be available in future
sessions, set it using the .Renviron file
with usethis::edit_r_environ()
Read more about the .Renviron here: ?.Renviron
line2route
## Not run: from <- c(-1.55, 53.80) # geo_code("leeds") to <- c(-1.76, 53.80) # geo_code("bradford uk") json_output <- route_cyclestreets(from = from, to = to, plan = "quietest", save_raw = TRUE) str(json_output) # what does cyclestreets give you? rf_lb <- route_cyclestreets(from, to, plan = "fastest") rf_lb@data plot(rf_lb) (rf_lb$length / (1000 * 1.61)) / # distance in miles (rf_lb$time / (60 * 60)) # time in hours - average speed here: ~8mph ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.