Set the edge weights of a travelcost graph

tc_set_edge_weights(x, fun, values)

Arguments

x

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

fun

function or string: a function or name of function. fun should accept two arguments, each an N x 2 matrix. The first gives the xy-coordinates of starting points, and the second gives the xy-coordinates of ending points. fun should return the weight (travel cost) between points. Only one of fun or values is required

values

numeric: A vector of edge weights. The length of values must be the same as the number of non-zero elements of the adjacency matrix. Ignored if fun is provided

Value

A tc_graph object with the edge weights set

See also

Examples

if (FALSE) { my_raster <- raster::raster(ext = raster::extent(c(152.75, 155.25, -56.25, -54.25)), res = c(0.5, 0.5), crs = "+proj=longlat") g <- tc_build_graph(my_raster) ## set weights according to great-circle distance g <- tc_set_edge_weights(g, fun = geosphere::distHaversine) }