Learn R Programming

leastcostpath (version 1.8.7)

create_lcp_network: Calculate least cost paths from specified origins and destinations

Description

Calculates least cost paths from each origins and destinations as specified in the neighbour matrix.

Usage

create_lcp_network(
  cost_surface,
  locations,
  nb_matrix = NULL,
  cost_distance = FALSE,
  parallel = FALSE,
  ncores = 1
)

Value

SpatialLinesDataFrame (sp package). The resultant object contains least cost paths calculated from each origins and destinations as specified in the neighbour matrix.

Arguments

cost_surface

TransitionLayer (gdistance package). Cost surface to be used in Least Cost Path calculation.

locations

SpatialPoints* (sp package). Potential locations to calculate Least Cost Paths from and to.

nb_matrix

matrix. 2 column matrix representing the index of origins and destinations to calculate least cost paths between.

cost_distance

logical. if TRUE computes total accumulated cost for each Least Cost Path. Default is FALSE.

parallel

logical. if TRUE, the Least Cost Paths will be calculated in parallel. Default is FALSE

ncores

numeric. Number of cores used if parallel is TRUE. Default value is 1.

Author

Joseph Lewis

Examples

Run this code

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')

lcp_network <- create_lcp_network(slope_cs, locations = locs,
nb_matrix = cbind(c(1, 4, 2, 1), c(2, 2, 4, 3)), cost_distance = FALSE, parallel = FALSE)

Run the code above in your browser using DataLab