ps_area: Area of spatial units

View source: R/ps_area.R

ps_areaR Documentation

Area of spatial units

Description

Calculate the area (or length) of each site in a spatial data set or phylospatial object. The main use of this function is to derive site weights for phylospatial(); see the site_weight argument of that function for details.

Usage

ps_area(x)

Arguments

x

A phylospatial object, a SpatRaster, or an sf object. Must have a defined coordinate reference system.

Details

Raster cell areas are calculated with cellSize, which accounts for variation in cell area across latitudes in longitude/latitude rasters. Polygon areas and line lengths are calculated with expanse and perim, respectively. Point sites have no area, so every point is given a value of 1.

Value

A numeric vector with one value per site (including unoccupied sites, for a phylospatial object), giving area in square kilometers for raster cells and polygons, or length in kilometers for lines.

See Also

phylospatial()

Examples

# cells in a longitude/latitude raster shrink toward the poles
r <- terra::rast(nrows = 10, ncols = 10, xmin = -120, xmax = -100, ymin = 30, ymax = 60)
a <- ps_area(r)
range(a)

# one way to use these values as site weights:
comm <- terra::rast(r, nlyrs = 3)
names(comm) <- c("sp1", "sp2", "sp3")
set.seed(1)
comm[] <- rbinom(terra::ncell(comm) * 3, 1, .5)
tree <- ape::rtree(3, tip.label = names(comm))
ps <- phylospatial(comm, tree, site_weight = sqrt(a))

phylospatial documentation built on Oct. 23, 2026, 1:06 a.m.