Learn R Programming

leastcostpath (version 1.7.4)

create_lcp: Calculate Least Cost Path from Origin to Destination

Description

Calculates a Least Cost Path from an origin location to a destination location. Applies Dijkstra's algorithm.

Usage

create_lcp(
  cost_surface,
  origin,
  destination,
  directional = FALSE,
  cost_distance = FALSE
)

Arguments

cost_surface

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

origin

SpatialPoints* (sp package) location from which the Least Cost Path is calculated. Only the first row is taken into account

destination

SpatialPoints* (sp package) location to which the Least Cost Path is calculated. Only the first row is taken into account

directional

logical. if TRUE Least Cost Path calculated from origin to destination only. If FALSE Least Cost Path calculated from origin to destination and destination to origin. Default is FALSE

cost_distance

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

Value

SpatialLinesDataFrame (sp package) of length 1 if directional argument is TRUE or 2 if directional argument is FALSE. The resultant object is the shortest route (i.e. least cost) between origin and destination using the supplied TransitionLayer.

References

Dijkstra, E. W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik. 1: 269-271.

Examples

Run this code
# NOT RUN {
r <- raster::raster(system.file('external/maungawhau.grd', package = 'gdistance'))

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

traverse_cs <- create_traversal_cs(r, neighbours = 16)

final_cost_cs <- slope_cs * traverse_cs

loc1 = cbind(2667670, 6479000)
loc1 = sp::SpatialPoints(loc1)

loc2 = cbind(2667800, 6479400)
loc2 = sp::SpatialPoints(loc2)

lcps <- create_lcp(cost_surface = final_cost_cs, origin = loc1,
destination = loc2, directional = FALSE, cost_distance = FALSE)
# }

Run the code above in your browser using DataLab