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

route

Plan routes on the transport network


Description

Takes origins and destinations, finds the optimal routes between them and returns the result as a spatial (sf or sp) object. The definition of optimal depends on the routing function used

Usage

route(
  from = NULL,
  to = NULL,
  l = NULL,
  route_fun = cyclestreets::journey,
  wait = 0,
  n_print = 10,
  list_output = FALSE,
  cl = NULL,
  ...
)

Arguments

from

An object representing origins (if lines are provided as the first argument, from is assigned to l)

to

An object representing destinations

l

Only needed if from and to are empty, in which case this should be a spatial object representing desire lines

route_fun

A routing function to be used for converting the straight lines to routes od2line()

wait

How long to wait between routes? 0 seconds by default, can be useful when sending requests to rate limited APIs.

n_print

A number specifying how frequently progress updates should be shown

list_output

If FALSE (default) assumes spatial (linestring) object output. Set to TRUE to save output as a list.

cl

Cluster

...

Arguments passed to the routing function, e.g. route_cyclestreets()

See Also

Examples

library(sf)
l = od_data_lines[2, ]
r_walk = route(l = l, route_fun = route_osrm, osrm.profile = "foot")
r_bike = route(l = l, route_fun = route_osrm, osrm.profile = "bike")
plot(r_walk$geometry)
plot(r_bike$geometry, col = "blue", add = TRUE)

# r_bc = route(l = l, route_fun = route_bikecitizens)
# plot(r_bc)
# route(l = l, route_fun = route_bikecitizens, wait = 1)
library(osrm)
r_osrm <- route(
  l = l,
  route_fun = osrmRoute,
  returnclass = "sf"
)
nrow(r_osrm)
plot(r_osrm)
sln <- stplanr::SpatialLinesNetwork(route_network_sf)
# calculate shortest paths
plot(sln)
plot(l$geometry, add = TRUE)
r_local <- stplanr::route(
  l = l,
  route_fun = stplanr::route_local,
  sln = sln
)
plot(r_local["all"], add = TRUE, lwd = 5)

stplanr

Sustainable Transport Planning

v0.8.2
MIT + file LICENSE
Authors
Robin Lovelace [aut, cre] (<https://orcid.org/0000-0001-5679-6536>), Richard Ellison [aut], Malcolm Morgan [aut] (<https://orcid.org/0000-0002-9488-9183>), Barry Rowlingson [ctb], Nick Bearman [ctb], Nikolai Berkoff [ctb], Scott Chamberlain [rev] (Scott reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/10), Mark Padgham [ctb], Andrea Gilardi [ctb] (<https://orcid.org/0000-0002-9424-7439>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.