Learn R Programming

stplanr (version 0.6.0)

sum_network_routes: Summarise shortest path between nodes on network

Description

Summarise shortest path between nodes on network

Usage

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

Other rnet: SpatialLinesNetwork, calc_catchment_sum(), calc_catchment(), calc_moving_catchment(), calc_network_catchment(), find_network_nodes(), gsection(), islines(), lineLabels(), overline2(), overline(), plot,SpatialLinesNetwork,ANY-method, plot,sfNetwork,ANY-method, sln2points(), sum_network_links()

Examples

Run this code
# NOT RUN {
# tests fail on dev version of dplyr
sln <- SpatialLinesNetwork(route_network)
weightfield(sln) # field used to determine shortest path
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
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)
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)
# }

Run the code above in your browser using DataLab