% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dem_derivatives.R
\name{dem_derivatives}
\alias{dem_derivatives}
\alias{northness}
\alias{eastness}
\title{Convenience functions for simple DEM derivatives}
\usage{
northness(asp_deg)

eastness(asp_deg)
}
\arguments{
\item{asp_deg}{Numeric vector of aspect values in degrees (\code{0:360}).}
}
\value{
Numeric vector of transformed values.
}
\description{
Functions to calculate simple DEM derivatives, currently \code{northness()} and
\code{eastness()} for transforming aspect degrees into the range \code{-1:1}.
}
\details{
\code{northness()} is a cosine transform of aspect degrees, with any flat aspect
values (\code{-1} if present) set to \code{90} degrees (east) as a neutral value:

\if{html}{\out{<div class="sourceCode">}}\preformatted{northness <- cos(asp_deg * pi / 180)
}\if{html}{\out{</div>}}

\code{eastness()} is a sine transform of aspect degrees, with any flat aspect
values (\code{-1} if present) set to \code{0} degrees (north) as a neutral value:

\if{html}{\out{<div class="sourceCode">}}\preformatted{eastness <- sin(asp_deg * pi / 180)
}\if{html}{\out{</div>}}
}
\note{
No validation is done on the input values. The caller is responsible for
ensuring input has valid type and range.
}
\examples{
## plot northness from slope-masked aspect for the Storm Lake AOI
f_dem <- system.file("extdata/storml_elev.tif", package="gdalraster")

# slope degrees
f_slp <- basename(tempfile(pattern = "storml_slp", fileext = ".tif"))
f_slp <- file.path("/vsimem", f_slp)
dem_proc("slope", f_dem, f_slp)

# aspect
f_asp <- basename(tempfile(pattern = "storml_asp", fileext = ".tif"))
f_asp <- file.path("/vsimem", f_asp)
dem_proc("aspect", f_dem, f_asp)

# compute masked aspect as an in-memory raster
expr <- "ifelse(SLOPE >= 2, ASPECT, -9999)"
(ds_masked_asp <- calc(expr = expr,
                       rasterfiles = c(f_slp, f_asp),
                       var.names = c("SLOPE", "ASPECT"),
                       fmt = "MEM",
                       dtName = "Float64",
                       nodata_value = -9999,
                       setRasterNodataValue = TRUE,
                       return_obj = TRUE))

# diverging palette for northness
# adapted from "heatmap3" in ltc-color-palettes
# https://github.com/loukesio/ltc-color-palettes
pal <- c("#d7191c", "#fdae61", "#ffffbf", "#abd9e9")

plot_raster(ds_masked_asp, legend = TRUE, col_map_fn = pal,
            pixel_fn = northness, na_col = "#2c7bb6",
            main = "Storm Lake AOI northness")

# clean up
ds_masked_asp$close()
deleteDataset(f_slp)
deleteDataset(f_asp)

}
\seealso{
\code{\link[=calc]{calc()}}, \code{\link[=dem_proc]{dem_proc()}}
}
