R/readGAEZslope.R

Defines functions readGAEZslope

### read GAEZ slope dataset

readGAEZslope <- function() {
  
  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)
}
pik-piam/geodata documentation built on Nov. 5, 2019, 12:21 a.m.