# Compute the area corresponding to a given number of cells.

Source:`R/terra_utils.R`

`nb_cell_to_area.Rd`

Compute the area corresponding to a given number of cells.

## Arguments

- raster_layer
`terra::rast()`

Raster object.- nb_cells
`numeric`

Number of raster cells.- unit
`unit`

object or a`character`

that can be coerced to a unit (see`unit`

package). 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

```
# \donttest{
habitat_data <- rast(
system.file("extdata", "habitat_hi_res.tif", package = "restoptr")
)
nb_cell_to_area(habitat_data, 20, unit = "ha")
#> 1.662578 [ha]
# }
```