cost_matrix: Create a cost based nearest neighbour matrix

View source: R/cost_matrix.R

cost_matrixR Documentation

Create a cost based nearest neighbour matrix

Description

Creates a cost based nearest neighbour matrix of k length for each provided location. This matrix can be used in the nb_matrix argument within the create_lcp_network function to calculate Least Cost Paths between origins and destinations.

Usage

cost_matrix(cost_surface, locations, k)

Arguments

cost_surface

TransitionLayer object (gdistance package). Cost surface to be used in calculating the k nearest neighbour

locations

SpatialPoints. Locations to calculate k nearest neighbours from

k

numeric number of nearest neighbours to be returned

Value

matrix cost-based k nearest neighbour for each location as specified in the locations argument. The resultant matrix can be used in the nb_matrix argument within the create_lcp_network function.

Author(s)

Joseph Lewis

Examples


r <- raster::raster(nrow=50, ncol=50,  xmn=0, xmx=50, ymn=0, ymx=50,
crs='+proj=utm')

r[] <- stats::runif(1:length(r))

slope_cs <- create_slope_cs(r, cost_function = 'tobler')

locs <- sp::spsample(as(raster::extent(r), 'SpatialPolygons'),n=5,'regular')

matrix <- cost_matrix(slope_cs, locs, 2)

lcp_network <- create_lcp_network(slope_cs, locations = locs,
nb_matrix = matrix, cost_distance = FALSE, parallel = FALSE)

leastcostpath documentation built on June 3, 2022, 9:06 a.m.