Learn R Programming

stplanr (version 0.5.0)

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 = stplanr::route_cyclestreet,
  n_print = 10,
  list_output = FALSE,
  ...
)

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()

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.

...

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

See Also

Other routes: line2routeRetry(), line2route(), route_cyclestreet(), route_dodgr(), route_graphhopper(), route_local(), route_transportapi_public()

Examples

Run this code
# NOT RUN {
# these lines require API keys/osrm instances
from <- c(-1.5484, 53.7941) # from <- geo_code("leeds rail station")
to <-   c(-1.5524, 53.8038) # to <- geo_code("university of leeds")
r <- route(from, to, route_fun = cyclestreets::journey)
plot(r)
# mapview::mapview(r) # for interactive map
r = route(cents_sf[1:3, ], cents_sf[2:4, ], route_fun = cyclestreets::journey) # sf points
summary(r$route_number)
route(flowlines_sf[1:4, ], route_fun = cyclestreets::journey) # lines
# with osrm backend - need to set-up osrm first - see routing vignette
route(pct::wight_lines_30, route_fun = osrm::osrmRoute, point_input = TRUE)
# with cyclestreets backend - need to set-up osrm first - see routing vignette
route(pct::wight_lines_30, route_fun = cyclestreets::journey, point_input = TRUE)
# }

Run the code above in your browser using DataLab