hf_shortPath: Least Cost Path Between Points

Description Usage Arguments Value Examples

View source: R/hf_shortPath.R

Description

A generalized method for calculating the "shortest" or least-cost paths between multiple start and end points.

Usage

1
hf_shortPath(x, origin, goal, fun = function(x) 1/mean(x), add_cost = FALSE)

Arguments

x

A RasterLayer with velocity or efficiency values.

origin

A POINT object from package sf specifying start locations

goal

A POINT object from package sf specifying end locations

fun

A function to calculate transition weights from the raster.

add_cost

Logical. Whether to return as a column the cost of travel between points.

Value

An sf object with least-cost line features. If add_cost = TRUE, the sf object also includes a cost column.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 

library(raster)
library(sf)

dem <- raster(system.file("extdata/slc.tif", package = "rHike"))

slope <- hf_slope(dem)

velocity <- hf_velocity(slope, hf = "campbell", decile = 30)

start_points <- st_sf(id = 1:3,
                      geometry = st_sfc(st_point(c(424350, 4514200)),
                                        st_point(c(426000, 4515000)),
                                        st_point(c(429000, 4516500)),
                                        crs = 26912))

end_points <- st_sf(id = 1:2,
                    geometry = st_sfc(st_point(c(426200, 4516400)),
                                      st_point(c(427600, 4515600)),
                                      crs = 26912))

short_paths <- hf_shortPath(velocity, start_points, end_points)

plot(dem)
plot(st_geometry(start_points), color = "red", add = TRUE)
plot(st_geometry(end_points), color = "blue", add = TRUE)
plot(st_geometry(short_paths), lty = 2, add = TRUE)


## End(Not run)

kbvernon/rHike documentation built on May 29, 2020, 7:22 p.m.