R/hf_velocity.R

Defines functions hf_velocity

Documented in hf_velocity

#' General hiking function for velocity
#'
#' A convenience wrapper for generating a velocity (distance per unit time)
#' raster based on various hiking functions.
#'
#' @usage hf_velocity(x, hf = "tobler", ...)
#'
#' @param x A \code{RasterLayer} with slope values, assumed to be in degrees.
#' @param hf \code{Character} The hiking function with which to compute velocity, either "tobler" (default) or "campbell."
#' @param ... Arguments to be passed to individual hiking functions.
#'
#' @return A \code{RasterLayer} of velocity values in km/hr.
#'
#' @export
#'
#' @examples
#' \dontrun{
#'
#' library(raster)
#'
#' dem <- raster(system.file("extdata/slc.tif", package = "rHike"))
#'
#' slope <- hf_slope(dem)
#'
#' tobler <- hf_velocity(slope, hf = "tobler", on.path = TRUE)
#' campbell <- hf_velocity(slope, hf = "campbell", decile = 30)
#'
#' plot(stack(tobler, campbell))
#'
#' }
#'
hf_velocity <- function(x, hf = "tobler", ...) {

  if(!inherits(x, "RasterLayer")) stop("x must be a raster.")

  if(!(hf %in% c("tobler", "campbell"))) stop("Unknown hiking function.")

  if(identical(hf, "tobler"))   v <- raster::calc(x, function(x) rHike::hf_tobler(x, ...))
  if(identical(hf, "campbell")) v <- raster::calc(x, function(x) rHike::hf_campbell(x, ...))

  return(v)

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