R/get_3Darray.R

Defines functions get_3Darray

Documented in get_3Darray

#' Assembles a 3D-array
#' 
#' This function returns a 3D-array which is an auxiliary
#' object when invoking \code{\link[igapfill]{applyGapfill}}.
#' 
#' @param path character with full path name of a directory containing files that
#'             can be read as RasterStacks
#'             
#' @export             
#'             
#' @importFrom raster stack
#' @importFrom raster nrow
#' @importFrom raster ncol
#' @importFrom raster nlayers
#' @importFrom raster getValues
#' @importFrom raster subset
#' 
#' @note This function may be useful when employing \code{\link[gapfill]{Gapfill}}
#' independently of the current package.
#'             
#' @seealso \code{\link[base]{array}}, \code{\link[gapfill]{Gapfill}}
#' 
#' @return An array with three dimensions             
#'             
get_3Darray <- function(path){
  STACK <- stack(path)
  ARRAY <- array(NA, dim = c(nrow(STACK), ncol(STACK), nlayers(STACK)))
  for( i in 1:nlayers(STACK) ){
    TEMP <- getValues(subset(STACK, i))
    ARRAY[,,i] <- TEMP
  }
  ARRAY
}

Try the igapfill package in your browser

Any scripts or data that you put into this service are public.

igapfill documentation built on June 8, 2025, 10:41 a.m.