
Compute the number of cells corresponding to a given area.
Source:R/terra_utils.R
area_to_nb_cells.RdCompute the number of cells corresponding to a given area.
Arguments
- raster_layer
terra::rast()Raster object.- area
numericArea.- unit
unitobject or acharacterthat can be coerced to a unit (seeunitpackage). Must be an area unit.
Details
The input raster must have a projected coordinate system. The distortion is
not corrected. It could be using the cellSize function of the terra
package, but this function is currently pretty slow for large rasters. If
your problem is at regional scale, the distortion should be negligible.
However, at larger scales, the best is to use an equal-area projected
coordinate system.
Examples
if (FALSE) { # \dontrun{
habitat_data <- rast(
system.file("extdata", "habitat_hi_res.tif", package = "restoptr")
)
area_to_nb_cells(habitat_data, 20, unit = "ha")
} # }