Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

area

Get the expanse (area) of individual polygons or for all (summed) raster cells


Description

Compute the area covered by polygons or for all raster cells that are not NA.

This method computes areas for longitude/latitude rasters, as the size of the cells is constant in degrees, but not in meters. But it can also be important if the coordinate reference system is planar, but not equal-area.

For vector data, the best way to compute area is to use the longitude/latitude CRS. This is contrary to (erroneous) popular belief that suggest that you should use a planar coordinate reference system. This is done automatically, if transform=TRUE.

Usage

## S4 method for signature 'SpatRaster'
expanse(x, unit="m", transform=TRUE)

## S4 method for signature 'SpatVector'
expanse(x, unit="m", transform=TRUE)

Arguments

x

SpatRaster or SpatVector

unit

character. One of "m", "km", or "ha"

transform

logical. If TRUE, planar CRS are transformed to lon/lat for accuracy

Value

numeric. The sum of the size of the cells that are not NA

See Also

cellSize for a the size of individual cells of a raster, that can be summed with global or with zonal to get the area for different categories.

Examples

### SpatRaster 
r <- rast(nrow=18, ncol=36)
v <- 1:ncell(r)
v[200:400] <- NA
values(r) <- v

# summed area in km2
expanse(r, unit="km")

r <- rast(ncol=90, nrow=45, ymin=-80, ymax=80)
m <- project(r, "+proj=merc")

expanse(m, unit="km")
expanse(m, unit="km", transform=FALSE)

### SpatVector
v <- vect(system.file("ex/lux.shp", package="terra"))

a <- expanse(v)
a
sum(a)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.