hf_hike | R Documentation |
Calculate the "shortest" or least-cost paths between multiple start and end points. For each from-point, the shortest path to every to-point is calculated.
hf_hike(x, from, to, add_cost = FALSE)
x |
a cost |
from |
an |
to |
an |
add_cost |
logical, whether to include a column of travel costs. |
An sf
object with least-cost LINE
features and two columns: from and to.
Values in the from- and to-columns are 1:nrow(from)
and 1:nrow(to)
, respectively.
If add_cost = TRUE
, the sf
object also includes a travel cost column.
library(sf) library(terra) fn <- system.file("extdata/red_butte_dem.tif", package = "hiker") red_butte_dem <- rast(fn) from <- st_sf(geometry = st_sfc(st_point(c(432000, 4514000)), st_point(c(434000, 4518000)), crs = 26912)) to <- st_sf(geometry = st_sfc(st_point(c(431000, 4515000)), st_point(c(436500, 4518500)), crs = 26912)) terrain <- hf_terrain(red_butte_dem) short_paths <- hf_hike(terrain, from, to) plot(red_butte_dem) plot(st_geometry(short_paths), lty = 2, add = TRUE) plot(st_geometry(from), pch = 19, col = "red2", add = TRUE) plot(st_geometry(to), pch = 19, col = "dodgerblue4", add = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.