Learn R Programming

raptr (version 0.0.3)

calcSpeciesAverageInPus: Calculate average value for species data in planning units

Description

This function calculates the average of species values in each planning unit. Be aware that using polygons with overlaps will result in inaccuracies. By default all polygons will be treated as having separate ids.

Usage

calcSpeciesAverageInPus(x, ...)

# S3 method for SpatialPolygons calcSpeciesAverageInPus(x, y, ids = seq_len(nlayers(y)), ncores = 1, gdal = FALSE, ...)

# S3 method for SpatialPolygonsDataFrame calcSpeciesAverageInPus(x, y, ids = seq_len(nlayers(y)), ncores = 1, gdal = FALSE, field = NULL, ...)

Arguments

x

"SpatialPolygons" or "SpatialPolygonsDataFrame" object.

...

not used.

y

"RasterLayer", "RasterStack", or "RasterBrick" object.

ids

"integer" vector of ids. Defaults to indices of layers in the y.

ncores

"integer" Number of cores to use for processing. Defaults to 1.

gdal

"logical" Should raster processing be performed using GDAL libraries? Defaults to FALSE.

field

"character" "integer" index or "character" name of column with planning unit ids. Valid only for "SpatialPolygonsDataFrame" objects. Default behaviour is to treat each polygon as a different planning unit.

Value

data.frame with sum of raster values in each polygon.

See Also

is.gdalInstalled, http://www.gdal.org/, http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries.

Examples

Run this code
# NOT RUN {
# simulate data
sim_pus <- sim.pus(225L)
sim_spp <- lapply(c('uniform','normal','bimodal'), sim.species, n=1, res=1, x=sim_pus)
# calculate average for 1 species
puvspr1.dat <- calcSpeciesAverageInPus(sim_pus, sim_spp[[1]])
# calculate average for multiple species
puvspr2.dat <- calcSpeciesAverageInPus(sim_pus, stack(sim_spp))
# }

Run the code above in your browser using DataLab