### read frontier forests
#' Read Frontier Forests data
#'
#' Reads the Frontier Forest shapefile. Output can also be converted to raster
#' data.
#'
#'
#' @usage readFF(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 Frontier Forest polygons or alternatively a raster dataset if
#' rasterize is set to TRUE
#' @author Ulrich Kreidenweis
#' @seealso \code{\link{readWDPA}}, \code{\link{readBH}}, \code{\link{readCPD}}
#' @examples
#'
#' \dontrun{readFF()}
#'
#' @export readFF
readFF <- 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, "/FF/", "Frontier_Forests.shp"), layer="Frontier_Forests")
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.