Skip to contents

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.

Usage

mosaic_chm(
  dsm,
  dtm = NULL,
  points = NULL,
  interpolation = c("Tps", "Kriging"),
  window_size = c(5, 5),
  mask = NULL,
  mask_soil = TRUE,
  verbose = TRUE
)

Arguments

dsm

A SpatRaster object representing the digital surface model. Must be a single-layer raster.

dtm

(optional) A SpatRaster object 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 sf object representing sample points for DTM interpolation. If provided, dtm will be interpolated using these points.

interpolation

(optional) A character string specifying the interpolation method to use when points are 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).

mask

(optional) A SpatRaster object used to mask the CHM and volume results. Default is NULL.

mask_soil

Is mask representing 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.