R/stitch_raster.R

Defines functions stitch_tiles

Documented in stitch_tiles

#' Process a directory of image files and stitch them together to form a single, large, raster.
#'
#' @param wd The directory containing tiles to stitch.
#' @param filetype File extension of the files to be stitched.
#' @param fun Function to use if cells overlap at tile borders. Can be min, max or mean.
#' @return Returns a single Raster object.
#' @seealso split_raster
#' @export
#' @examples Coming soon.

stitch_tiles<-function(wd, filetype="tif", fun=mean){

  setwd(wd)
  temp<-list.files(pattern=paste0("*.",filetype))
  rast.list<-list()
  for(i in 1:length(temp)) {
    rast.list[[i]] <- raster(temp[i])
    }
  merged<-do.call(mosaic, c(rast.list, fun=fun))
  return(merged)

}
simon-tarr/island documentation built on May 6, 2019, 8:05 p.m.