## create area information that can be later on, so that it doesn't have to be calculated each time:
# is a list with resolution entries
#' Create area grid files
#'
#' Calculates areas per grid cell for the specified resolution and stores the
#' output at the specified location. These can be used by perc2area for the
#' conversion of percentage values to absolute km2 values.
#'
#'
#' @usage createArea(res=0.08333333,
#' folder="/p/projects/landuse/users/ulrichk/geodatafiles")
#' @param res The resolution to calculate the area for. Can also be a vector of
#' different resolutions
#' @param folder Folder to store the output in. Filename is created in the
#' format: "area0.08333333.grd""
#' @return Output is saved to disk
#' @author Ulrich Kreidenweis
#' @seealso \code{\link{perc2area}}
#' @examples
#'
#' \dontrun{createArea()}
#'
#' @export createArea
#' @importFrom raster area
createArea <- function(res=0.08333333, folder="/p/projects/landuse/users/ulrichk/geodatafiles") {
# areafile <- list()
for (r in res){
A <- raster::raster()
raster::res(A) <- r
raster::extent(A) <- c(-180,180,-90,90)
area(A, filename=paste0(folder,"/area", r, ".grd"))
}
# if(is.null(file)) {return(areafile)
# } else save(areafile, file=file)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.