tc_shortest_paths.Rd
Calculate the shortest paths between points on a raster
tc_shortest_paths(x, from, to, direction = "out")
x | tc_graph: an object of class |
---|---|
from | numeric or matrix: the points to calculate travel costs from. A two-element numeric vector or a 2-column matrix, or anything else accepted by |
to | numeric or matrix: the points to calculate travel costs to. If missing, paths to all points in the raster will be returned |
direction | string:
|
A list of paths (two-column matrices giving x and y points)
my_raster <- raster::raster(ext = raster::extent(c(153, 155, -56, -54)), res = c(0.5, 0.5), crs = "+proj=longlat") g <- tc_build_graph(my_raster) ## set random edge weights g <- tc_set_edge_weights(g, values = runif(sum(tc_adj_matrix(g) > 0))) ## calculate shortest path p <- tc_shortest_paths(g, from = c(153, -54), to = c(155, -56)) plot(p[[1]][, 1], p[[1]][, 2], type = "l", xlab = "", ylab = "")