| pol2pam | R Documentation |
This function takes spatial polygon objects (typically species distribution polygons) and converts them into a presence-absence matrix (PAM) using a rasterization approach at a specified resolution. The function is particularly useful for biodiversity and biogeography analyses.
pol2pam(poly, taxon_attribute, resolution, polymask = NULL)
poly |
Spatial polygon object (SpatialPolygonsDataFrame, sf, etc.) containing species or taxon distribution data. |
taxon_attribute |
Character. The name of the column in 'poly' that contains taxon identifiers (species, genera, etc.). |
resolution |
Numeric. The resolution for the output raster in coordinate system units (cell size). |
polymask |
Optional. A spatial polygon object used to mask and crop the resulting raster. If NULL, no masking is applied. |
The function works by:
Creating a base raster with the specified resolution and extent
Splitting polygons by taxon attribute
Rasterizing each taxon's distribution using exact extraction
Stacking individual rasters into a multi-layer raster
Applying optional masking with polymask
Converting the raster stack to a PAM using bamm::models2pam
A PAM (Presence-Absence Matrix) object of class 'pam' from the 'bamm' package containing:
matrix: Presence-absence matrix (1/0) where rows represent grid cells
and columns represent taxa
richness: Richness pattern across grid cells
sparse: Logical indicating if the matrix is stored in sparse format
cell_coordinates: Coordinates of each grid cell
This function requires the following packages: raster, exactextractr, purrr, and bamm. The input polygons are converted to SpatialPolygonsDataFrame if they aren't already.
models2pam, raster,
exact_extract
## Not run:
# Load required libraries
library(raster)
# Example with sample data
uicn <- readRDS(system.file("extdata/uicn.rds",package = "bamm"))
sudam <- readRDS(system.file("extdata/suam.rds",package = "bamm"))
# Convert to PAM with 0.5 degree resolution
pam_result <- bamm::pol2pam(poly = uicn,
taxon_attribute = "binomial",
resolution = 0.5,
polymask = NULL)
# With masking polygon
pam_masked <- pol2pam(poly = uicn,
taxon_attribute = "binomial",
resolution = 0.5,
polymask = sudam)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.