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.
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 polys2comm; or point occurrence data frame for points2comm, with at least three columns:
Column 1: species (listing the taxon names)
Column 2: decimallongitude (corresponding to decimal longitude)
Column 3: decimallatitude (corresponding to decimal latitude)
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.
Returns
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.
Examples
fdir <- system.file("NGAplants", package="phyloregion")files <- file.path(fdir, dir(fdir))ras <- rast2comm(files)# Note, this function generates# a list of two objectshead(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 objectshead(pt[[1]])
See Also
mapproject for conversion of latitude and longitude into projected coordinates system. long2sparse for conversion of community data.