Learn R Programming

movecost (version 3.0.0)

mc_network: Least-cost network between multiple locations

Description

Computes least-cost paths between multiple locations, either between all unique pairs (type = "allpairs") or from each location to its closest (cost-wise) neighbour (type = "neigh"), together with the full origin-to-origin cost matrix and, optionally, a path-density raster.

Usage

mc_network(
  surface,
  nodes,
  type = c("allpairs", "neigh"),
  density = FALSE,
  time = "h"
)

Value

An object of class movecost_network, a list with components

  • paths: sf lines with from, to, cost, and length attributes;

  • cost.matrix: full asymmetric cost matrix between locations (in the unit of the cost function; for time-based functions, in the unit selected via time);

  • density.count, density.perc: path-density rasters (SpatRaster; NULL unless density = TRUE);

  • nodes: the input locations (sf), with a node column holding the index (1..n) that matches the row and column names of cost.matrix and the node labels drawn by plot();

  • metadata used by the plot method.

Plot it at any time with plot() (see plot.movecost_network).

Arguments

surface

a movecost_surface object created by mc_surface.

nodes

locations to be connected (sf points, SpatVector, or legacy SpatialPointsDataFrame); at least two.

type

"allpairs" (default) for LCPs between all unique pairs of locations (in both directions, since costs are anisotropic), or "neigh" for LCPs from each location to its cost-wise nearest neighbour.

density

TRUE or FALSE (default): also compute the path-density rasters.

time

unit for time-based cost functions: "h" (hours, default) or "m" (minutes).

Details

The graph stored in the mc_surface object is reused throughout: the cost matrix requires a single multi-source query and the paths one Dijkstra run per location, whereas movecost <= 2.x rebuilt the conductance matrix before any of this could start. For n locations this reduces the dominant cost from O(n) full matrix constructions to zero.

The path-density raster (density = TRUE) counts, for each cell, how many least-cost paths traverse it; the percentage version expresses the count against the total number of paths. Density is computed exactly, from the graph vertices of each path (no rasterisation approximation).

See Also

mc_surface, plot.movecost_network

Examples

Run this code
dtm <- mc_volc()
destin <- mc_destin_loc()

surf <- mc_surface(dtm, funct = "t", move = 8)
nw <- mc_network(surf, nodes = destin, type = "allpairs")

nw$cost.matrix              # asymmetric origin-to-origin costs
plot(nw)

# network connecting each site to its cost-wise nearest neighbour
nw2 <- mc_network(surf, nodes = destin, type = "neigh")
plot(nw2)

Run the code above in your browser using DataLab