Learn R Programming

terra (version 0.4-3)

area: Area and perimeter

Description

Compute area of polygons or and the surfacer area or raster cells. Computing the surface area of raster cells is only relevant for longitude/latitude rasters. For planar data, the cell area is constant, can be computed with prod(res(x)). For polygons, the area of each geometry is returned.

The perimeter method works only on SpatVector objects, and computes the length of lines or the perimeter of polygons.

Usage

# S4 method for SpatRaster
area(x, filename="", overwrite=FALSE,  wopt=list(), ...)

# S4 method for SpatVector area(x, ...) # S4 method for SpatVector perimeter(x)

Arguments

x

SpatRaster or SpatVector

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

If the coordinate reference system is longitude/latitude the values returned are in square meter for area and meter for perimeter.

In other cases, the unit is set by coordinate references system. In most cases it is meter too.

Examples

Run this code
# NOT RUN {
f <- system.file("exdata/lux.shp", package="terra")
v <- vect(f)
a <- area(v)
a
sum(a)
perimeter(v)
# }

Run the code above in your browser using DataLab