This function constructs a graph for least-cost paths analysis. This function is specifically designed for situations in which the aim is to calculate least-cost distances between points on a raster.

lcp_graph_surface(surface, cost, verbose = TRUE)

Arguments

surface

A raster for which to construct the graph. There are some constraints on the form of this raster if the costs of movement between cells are derived from lcp_costs (see below).

cost

A sparse dsCMatrix-class matrix that defines the cost of movement between connected cells on the surface (see lcp_costs).

verbose

A logical function that defines whether or not to print messages to the console to relay function progress.

Value

The function returns a named list that defines the graph (see makegraph)

Details

This is a wrapper for the makegraph function.

Author

Edward Lavender

Examples

#### Step (1): Define cost surface
# We will consider the distances between connected cells in the example
# ... 'dat_gebco' raster as a measure of cost. For this, we will focus on a
# ... specific area (for speed), within which we need to
# ... we need to regularise the resolution:
boundaries <- raster::extent(707884.6, 709884.6, 6253404, 6255404)
blank <- raster::raster(boundaries, res = c(5, 5))
r <- raster::resample(dat_gebco, blank)
#> Warning: aggregation factor is larger than the number of columns
#> Warning: aggregation factor is larger than the number of rows
#> Error in .intersectExtent(x, y, validate = TRUE): Objects do not intersect
# Define costs
costs <- lcp_costs(r)
#> flapper::lcp_costs() called (@ 2023-08-29 15:43:56)... 
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'res': object 'r' not found

#### Step (2): Make graph for LCP analysis
graph <- lcp_graph_surface(surface = r, cost = costs$dist_total)
#> flapper::lcp_graph_surface() called (@ 2023-08-29 15:43:56)... 
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'ncell': object 'r' not found

#### Step (3): Implement LCP analysis around point on Raster*
# ... e.g., via lcp_from_point()