leastcostpath - version 1.7.4
=============================
The R library leastcostpath provides the functionality to calculate Cost Surfaces based on multiple cost functions that approximate the difficulty of moving across a landscape. Furthermore, the attraction/repulsion of landscape features can be incorporated into the Cost Surfaces, as well as barriers that inhibit movement.
Cost Surfaces can be used to calculate Least Cost Paths, which are often, but not exclusively, used in archaeological research. leastcostpath also provides the functionality to calculate movement potential within a landscape through the implementation of From-Everywhere-to-Everywhere (FETE) (White and Barber, 2012), Cumulative Cost Paths (Verhagen, 2013), and Least Cost Path calculation within specified distance bands (Llobera, 2015). Furthermore, the library allows for the calculation of stochastic least cost paths and wide least cost paths.
Lastly, the library provides functionality to validate the accuracy of computed Least Cost Paths relative to another path.
This package is built on classes and functions provided in the R package gdistance (Van Etten, 2017).
Functions currently in development:
Functions recently added:
#install.packages("devtools")
library(devtools)
install_github("josephlewis/leastcostpath")
library(leastcostpath)
library(leastcostpath)
r <- raster::raster(system.file('external/maungawhau.grd', package = 'gdistance'))
slope_cs <- create_slope_cs(r, cost_function = 'tobler')
slope_cs_10 <- create_slope_cs(r, cost_function = 'tobler', max_slope = 10)
loc1 = cbind(2667670, 6479000)
loc1 = sp::SpatialPoints(loc1)
loc2 = cbind(2667800, 6479400)
loc2 = sp::SpatialPoints(loc2)
lcps <- create_lcp(cost_surface = slope_cs, origin = loc1, destination = loc2, directional = FALSE)
plot(raster(slope_cs))
plot(lcps[1,], add = T, col = "red") # location 1 to location 2
plot(lcps[2,], add = T, col = "blue") # location 2 to location 1
cc <- create_cost_corridor(slope_cs, loc1, loc2)
plot(cc)
plot(loc1, add = T)
plot(loc2, add = T)
locs <- sp::spsample(as(raster::extent(r), 'SpatialPolygons'),n=10,'regular')
lcp_network <- create_FETE_lcps(cost_surface = slope_cs, locations = locs,
cost_distance = FALSE, parallel = FALSE)
plot(raster(slope_cs))
plot(locs, add = T)
plot(lcp_network, add = T)
locs <- sp::spsample(as(raster::extent(r), 'SpatialPolygons'),n=1,'random')
lcp_network <- create_CCP_lcps(cost_surface = slope_cs, location = locs, distance = 50,
radial_points = 10, cost_distance = FALSE, parallel = FALSE)
plot(raster(slope_cs))
plot(locs, add = T)
plot(lcp_network, add = T)
locs <- sp::spsample(as(raster::extent(r), 'SpatialPolygons'),n=1,'random')
lcp_network <- create_banded_lcps(cost_surface = slope_cs, location = locs, min_distance = 20,
max_distance = 50, radial_points = 10, cost_distance = FALSE, parallel = FALSE)
plot(raster(slope_cs))
plot(locs, add = T)
plot(lcp_network, add = T)
cumulative_lcps <- create_lcp_density(lcps = lcp_network, raster = r, rescale = FALSE)
plot(cumulative_lcps)
locs <- sp::spsample(as(raster::extent(r), 'SpatialPolygons'),n=5,'regular')
mat <- cbind(c(1, 4, 2, 1), c(2, 2, 4, 3))
lcp_network <- create_lcp_network(slope_cs, locations = locs,
nb_matrix = mat, cost_distance = FALSE, parallel = FALSE)
locs <- sp::spsample(as(raster::extent(r), 'SpatialPolygons'),n=2,'random')
stochastic_lcp <- replicate(n = 10, create_stochastic_lcp(cost_surface = slope_cs,
origin = locs[1,], destination = locs[2,], directional = FALSE))
stochastic_lcp <- do.call(rbind, stochastic_lcp)
n <- 3
slope_cs <- create_slope_cs(r, cost_function = 'tobler', neighbours = wide_path_matrix(n))
loc1 = cbind(2667670, 6479000)
loc1 = sp::SpatialPoints(loc1)
loc2 = cbind(2667800, 6479400)
loc2 = sp::SpatialPoints(loc2)
lcps <- create_wide_lcp(cost_surface = slope_cs, origin = loc1,
destination = loc2, path_ncells = n)
cost_surface <- create_slope_cs(r, cost_function = 'tobler') %>%
"*" (create_traversal_cs(r)) %>%
"*" (create_feature(raster = r, locations = loc1, x = seq(200, 1, length.out = 20))
lcp <- cost_surface %>%
create_lcp(cost_surface = . loc1, loc2)
cost_corridor <- cost_surface %>%
create_cost_corridor(., loc1, loc2)
locs <- sp::spsample(as(extent(r), 'SpatialPolygons'),n=10,'regular')
lcp_network <- cost_surface %>%
create_FETE_lcps(cost_surface = final_cost_cs, locations = locs,cost_distance = FALSE, parallel = FALSE)
cumulative_cost_paths <- cost_surface %>%
create_FETE_lcps(cost_surface = final_cost_cs, locations = locs,cost_distance = FALSE, parallel = FALSE) %>%
create_cumulative_lcps(lcps = ., raster = r, rescale = FALSE)
Please email josephlewis1992[at]gmail.com to provide your feedback or suggest functionality that you would like implemented.
Please cite as:
Lewis, J. (2020) leastcostpath: Modelling Pathways and Movement Potential Within a Landscape (version 1.7.4).
Available at: https://cran.r-project.org/web/packages/leastcostpath/index.html