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

route(
  from = NULL,
  to = NULL,
  l = NULL,
  route_fun = stplanr::route_cyclestreets,
  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_cyclestreets()

See also

Examples

# \donttest{ # 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") r1 <- route(from, to, route_fun = cyclestreets::journey)
#> Most common output is simpleError
#> These routes failed: 1
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): Error: No valid API key was supplied. Please go to https://www.cyclestreets.net/api/apply/ to apply for an API key.>
r2 <- route(from, to, route_fun = cyclestreets::journey, plan = "quietest")
#> Most common output is simpleError
#> These routes failed: 1
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): Error: No valid API key was supplied. Please go to https://www.cyclestreets.net/api/apply/ to apply for an API key.>
plot(r1)
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Error in plot.window(...): need finite 'xlim' values
plot(r2)
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Error in plot.window(...): need finite 'xlim' values
r = route(cents_sf[1:3, ], cents_sf[2:4, ], route_fun = cyclestreets::journey) # sf points
#> Most common output is simpleError
#> These routes failed: 1, 2, 3
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): Error: No valid API key was supplied. Please go to https://www.cyclestreets.net/api/apply/ to apply for an API key.>
summary(r$route_number)
#> Length Class Mode #> 0 NULL NULL
route(flowlines_sf[1:4, ], route_fun = cyclestreets::journey, plan = "quietest")
#> Most common output is simpleError
#> These routes failed: 1, 2, 3, 4
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): Error: No valid API key was supplied. Please go to https://www.cyclestreets.net/api/apply/ to apply for an API key.>
#> NULL
route(flowlines_sf[1:4, ], route_fun = cyclestreets::journey, plan = "balanced")
#> Most common output is simpleError
#> These routes failed: 1, 2, 3, 4
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): Error: No valid API key was supplied. Please go to https://www.cyclestreets.net/api/apply/ to apply for an API key.>
#> NULL
# with osrm backend - need to set-up osrm first - see routing vignette route(pct::wight_lines_30, route_fun = osrm::osrmRoute, point_input = TRUE)
#> Most common output is simpleError
#> These routes failed: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): unused argument (point_input = TRUE)>
#> NULL
# with cyclestreets backend - need to set-up osrm first - see routing vignette route(pct::wight_lines_30, route_fun = cyclestreets::journey, point_input = TRUE)
#> Most common output is simpleError
#> These routes failed: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
#> The first of which was:
#> <simpleError in FUN(ldf[i, 1:2], ldf[i, 3:4], ...): unused argument (point_input = TRUE)>
#> NULL
# }