### read centers of plant diversity
#' Read Centres of Plant Diversity (CPD) data
#'
#' Reads the Centres of Plant diversity shapefile. Output can be converted to
#' raster data.
#'
#'
#' @usage readCPD(rasterize=F, rast=NULL, res=NULL, getCover=F, rCache=T,
#' wCache=T)
#' @param rasterize if TRUE, polygons are rasterized
#' @param rast specify a raster here that should be used for rasterizing the
#' polygons accordingly
#' @param res alternatively to rast the raster resolution can be set
#' @param getCover if TRUE, returns the share of each cell covered by protected
#' areas
#' @param rCache TRUE: read the data from cache if available
#' @param wCache write the data to cache if it has been newly created
#' @return The CPD polygons or alternatively a raster dataset if rasterize is
#' set to TRUE
#' @author Ulrich Kreidenweis
#' @seealso \code{\link{readWDPA}}, \code{\link{readBH}}, \code{\link{readFF}}
#' @examples
#'
#' \dontrun{readCPD()}
#'
#' @export readCPD
readCPD <- function(rasterize=F, rast=NULL, res=NULL, getCover=F, rCache=T, wCache=T) {
dat <- NULL
if(rCache) dat <- readCache(); fromcache=T
if(is.null(dat)) {
dat <- rgdal::readOGR(paste0(geodata$config$mainfolder, "/CPD/", "CPD_2013.shp"), layer="CPD_2013" )
fromcache=F
if(rasterize) {
if ( (is.null(rast) & is.null(res)) | (!is.null(rast) & !is.null(res)) ) stop("Either 'rast' or 'res' have to be specified")
if(!is.null(rast)) {
if (!attr(class(r), "package") == "raster") stop("'rast' has to be a raster object")
r <- rast
} else if (!is.null(res)) {
r <- raster::raster()
raster::res(r) <- res
}
dat <- raster::rasterize(dat, r, getCover=getCover)
}
}
if (wCache & !fromcache) writeCache(dat)
return(dat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.