This function calculates the canopy height model (CHM) and the volume for a given digital surface model (DSM) raster layer. Optionally, a digital terrain model (DTM) can be provided or interpolated using a set of points or a moving window.
Arguments
- dsm
A
SpatRasterobject representing the digital surface model. Must be a single-layer raster.- dtm
(optional) A
SpatRasterobject representing the digital terrain model. Must be a single-layer raster. If not provided, it can be interpolated from points or created using a moving window.- points
(optional) An
sfobject representing sample points for DTM interpolation. If provided,dtmwill be interpolated using these points.- interpolation
(optional) A character string specifying the interpolation method to use when
pointsare provided. Options are "Kriging" (default) or "Tps" (Thin Plate Spline).- window_size
An integer (meters) specifying the window size (rows and columns, respectively) for creating a DTM using a moving window. Default is c(10, 10).
- ground_quantile
Numeric value between
0and1indicating the quantile threshold for ground point selection in the CHM computation. Lower values (e.g.,0) retain the lowest ground points, while higher values (e.g.,1) consider higher ground elevations. Default is0, which uses the lowest points within each window.- mask
(optional) A
SpatRasterobject used to mask the CHM and volume results. Default is NULL.- mask_soil
Is
maskrepresenting a soil mask (eg., removing plants)? Default is TRUE.- verbose
Return the progress messages. Default is TRUE.
Value
A SpatRaster object with three layers: dtm (digital terrain
model), height (canopy height model), and volume.
Details
The function first checks if the input dsm is a valid single-layer
SpatRaster object. If dtm is not provided, The function generates a
Digital Terrain Model (DTM) from a Digital Surface Model (DSM) by
downsampling and smoothing the input raster data. It iterates over the DSM
matrix in windows of specified size, finds the minimum value within each
window, and assigns these values to a downsampled matrix. After downsampling,
the function applies a mean filter to smooth the matrix, enhancing the visual
and analytical quality of the DTM. Afterwards, DTM is resampled with the
original DSM.
If both dsm and dtm are provided, the function ensures they have the same
extent and number of cells, resampling dtm if necessary. The CHM is then
calculated as the difference between dsm and dtm, and the volume is
calculated by multiplying the CHM by the pixel size. The results are
optionally masked using the provided mask.
