Learn R Programming

movecost (version 3.0.0)

mc_paths: Least-cost paths from an origin to one or more destinations

Description

Computes least-cost path(s) (LCPs) from an origin to one or more destination locations, reusing the graph stored in a mc_surface object. Because terrain costs are anisotropic, the path back from a destination to the origin can differ from the outward path; set return.base = TRUE to also compute the return paths.

Usage

mc_paths(surface, origin, destin, return.base = FALSE, time = "h")

Value

An object of class movecost_paths, a list with components

  • paths: sf lines with cost, length and (for time-based functions) cost_hms attributes;

  • paths.back: sf lines of the return paths (NULL unless return.base = TRUE);

  • destin: copy of the destination locations with cost (and cost_hms) appended;

  • origin: the origin (sf);

  • metadata used by the plot method.

Plot it at any time with plot() (see plot.movecost_paths); no computation is re-run.

Arguments

surface

a movecost_surface object created by mc_surface.

origin

single origin location (sf points, SpatVector, or legacy SpatialPointsDataFrame); if more than one feature is supplied, the first is used.

destin

destination location(s) (same accepted classes).

return.base

TRUE or FALSE (default): also compute the least-cost paths from each destination back to the origin.

time

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

Details

Each returned path carries its accumulated cost (in the unit of the surface's cost function; for time-based functions, in the unit selected via time) and its length. For time-based functions a cost_hms column additionally expresses the cost in sexagesimal format (HH:MM:SS). The same attributes are appended to the returned copy of the destination locations, mirroring the dest.loc.w.cost output of movecost <= 2.x.

See Also

mc_surface, plot.movecost_paths, mc_rank, mc_network

Examples

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

surf <- mc_surface(dtm, funct = "t", move = 8)
lcp <- mc_paths(surf, origin = start, destin = destin)

lcp$paths          # sf object: costs, lengths, geometries
plot(lcp)

# paths back to the origin (anisotropy makes them differ):
lcp2 <- mc_paths(surf, start, destin[2, ], return.base = TRUE)
plot(lcp2)

Run the code above in your browser using DataLab