create_lcp: Calculate Least-cost Path from Origin to Destinations

View source: R/create_lcp.R

create_lcpR Documentation

Calculate Least-cost Path from Origin to Destinations

Description

Calculates the Least-cost path from an origin location to one or more destination locations. Applies Dijkstra's algorithm as implemented in the igraph R package.

Usage

create_lcp(
  x,
  origin,
  destination,
  cost_distance = FALSE,
  check_locations = FALSE
)

Arguments

x

conductanceMatrix

origin

sf 'POINT' or 'MULTIPOINT', SpatVector, data.frame or matrix containing the origin coordinates. Only the first row of the supplied object is used as the origin.

destination

sf 'POINT' or 'MULTIPOINT', SpatVector, data.frame or matrix containing the destination coordinates. If the object contains multiple coordinates then least-cost paths will be calculated from the origin to all destinations

cost_distance

logical if TRUE computes total accumulated cost from origin to the destinations. FALSE (default)

check_locations

logical if TRUE checks if origin and destination are traversable by the least-cost path. FALSE (default)

Value

sf Least-cost path from origin and destinations based on the supplied conductanceMatrix

Author(s)

Joseph Lewis

Examples


r <- terra::rast(system.file("extdata/SICILY_1000m.tif", package="leastcostpath"))

slope_cs <- create_slope_cs(x = r, cost_function = "tobler", neighbours = 4)

locs <- sf::st_sf(geometry = sf::st_sfc(
sf::st_point(c(839769, 4199443)),
sf::st_point(c(1038608, 4100024)),
sf::st_point(c(1017819, 4206255)),
sf::st_point(c(1017819, 4206255)),
crs = terra::crs(r)))

lcps <- create_lcp(x = slope_cs, origin = locs[1,], destination = locs)

josephlewis/leastcostpath documentation built on Oct. 18, 2023, 2:03 p.m.