Learn R Programming

raster (version 2.5-8)

area: Size of cells

Description

Compute the approximate surface area of cells in an unprojected (longitude/latitude) Raster object. It is an approximation because area is computed as the height (latitudial span) of a cell (which is constant among all cells) times the width (longitudinal span) in the (latitudinal) middle of a cell. The width is smaller at the poleward side than at the equator-ward side of a cell. This variation is greatest near the poles and the values are thus not very precise for very high latitudes.

Usage

# S4 method for RasterLayer
area(x, filename="", na.rm=FALSE, weights=FALSE, ...)

# S4 method for RasterStackBrick area(x, filename="", na.rm=FALSE, weights=FALSE, ...)

Arguments

x

Raster* object

filename

character. Filename for the output Raster object (optional)

na.rm

logical. If TRUE, cells that are NA are ignored

weights

logical. If TRUE, the area of each cells is divided by the total area of all cells that are not NA

...

additional arguments as for writeRaster

Value

RasterLayer or RasterBrick. Cell values represent the size of the cell in km2, or the relative size if weights=TRUE

Details

If x is a RasterStack/Brick, a RasterBrick will be returned if na.rm=TRUE. However, if na.rm=FALSE, a RasterLayer is returned, because the values would be the same for all layers.

Examples

Run this code
# NOT RUN {
r <- raster(nrow=18, ncol=36)
a <- area(r)
# }

Run the code above in your browser using DataLab