Summarise shortest path between nodes on network

sum_network_routes(
  sln,
  start,
  end,
  sumvars = weightfield(sln),
  combinations = FALSE
)

Arguments

sln

The SpatialLinesNetwork to use.

start

Integer of node indices where route ends.

end

Integer of node indices where route ends.

sumvars

Character vector of variables for which to calculate summary statistics. The default value is weightfield(sln).

combinations

Boolean value indicating if all combinations of start and ends should be calculated. If TRUE then every start Node ID will be routed to every end Node ID. This is faster than passing every combination to start and end. Default is FALSE.

Details

Find the shortest path on the network between specified nodes and returns a SpatialLinesdataFrame containing the path(s) and summary statistics of each one.

The start and end arguments must be integers representing the node index. To find which node is closes to a geographic point, use find_nearest_node()

See also

Examples

# tests fail on dev version of dplyr sln <- SpatialLinesNetwork(route_network)
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
weightfield(sln) # field used to determine shortest path
#> [1] "length"
shortpath <- sum_network_routes(sln, start = 1, end = 50, sumvars = "length") plot(shortpath, col = "red", lwd = 4)
plot(sln, add = TRUE)
# with sf objects sln <- SpatialLinesNetwork(route_network_sf) weightfield(sln) # field used to determine shortest path
#> [1] "length"
shortpath <- sum_network_routes(sln, start = 1, end = 50, sumvars = "length") plot(sf::st_geometry(shortpath), col = "red", lwd = 4)
plot(sln, add = TRUE)
# find shortest path between two coordinates sf::st_bbox(sln@sl)
#> xmin ymin xmax ymax #> -1.550964 53.802478 -1.510987 53.830414
start_coords <- c(-1.546, 53.826) end_coords <- c(-1.519, 53.816) plot(sln)
plot(sf::st_point(start_coords), cex = 3, add = TRUE)
plot(sf::st_point(end_coords), cex = 3, add = TRUE)
nodes <- find_network_nodes(sln, rbind(start_coords, end_coords)) shortpath <- sum_network_routes(sln, nodes[1], nodes[2]) plot(sf::st_geometry(shortpath), col = "red", lwd = 3, add = TRUE)