rast2comm {phyloregion} | R Documentation |
Convert raw input distribution data to community
Description
The functions points2comm
, polys2comm
, rast2comm
provide convenient interfaces to convert raw distribution data often
available as point records, polygons and raster layers,
respectively, to a community composition data frame at varying spatial grains
and extents for downstream analyses.
Usage
rast2comm(files)
polys2comm(dat, res = 0.25, pol.grids = NULL, ...)
points2comm(dat, res = 0.25, pol.grids = NULL, ...)
Arguments
files |
list of SpatRaster layer objects with the same spatial extent and resolution. |
dat |
layers of merged maps corresponding to species polygons for
|
res |
the grain size of the grid cells in decimal degrees (default). |
pol.grids |
if specified, the vector polygon of grid cells with a column labeled “grids”. |
... |
Further arguments passed to or from other methods. |
Value
Each of these functions generate a list of two objects as follows:
comm_dat: (sparse) community matrix
map: vector or raster of grid cells with the values per cell for mapping.
See Also
mapproject
for conversion of
latitude and longitude into projected coordinates system.
long2sparse
for conversion of community data.
Examples
fdir <- system.file("NGAplants", package="phyloregion")
files <- file.path(fdir, dir(fdir))
ras <- rast2comm(files) # Note, this function generates
# a list of two objects
head(ras[[1]])
require(terra)
s <- vect(system.file("ex/nigeria.json", package="phyloregion"))
sp <- random_species(100, species=5, pol=s)
pol <- polys2comm(dat = sp)
head(pol[[1]])
library(terra)
s <- vect(system.file("ex/nigeria.json", package="phyloregion"))
set.seed(1)
m <- as.data.frame(spatSample(s, 1000, method = "random"),
geom = "XY")[-1]
names(m) <- c("lon", "lat")
species <- paste0("sp", sample(1:100))
m$taxon <- sample(species, size = nrow(m), replace = TRUE)
pt <- points2comm(dat = m, res = 0.5) # This generates a list of two objects
head(pt[[1]])