Calculate the travel cost from one or more points to each point on a raster

tc_cost(x, from, direction = "out")

Arguments

x

tc_graph: an object of class tc_graph, as returned by tc_build_graph()

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 raster::cellFromXY()

direction

string:

  • "out" - calculate travel cost outwards from the 'from' points to each point on the raster

  • "in" - calculate travel cost from each point on the raster to each of the 'from' points

  • "both" the sum of "out" and "in"

Value

A raster layer (if from is one point) or brick (if from is more than one point)

See also

Examples

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 travel cost cx <- c(154, -55) D <- tc_cost(g, from = cx)