Skip to main content
1 of 3
Jeffrey Evans
  • 32k
  • 2
  • 48
  • 97

The terra package has a new object class SpatRasterCollection for image collections than can be used with terra::mosaic or terra::merge. This greatly simplifies mosaic operations. Here is an example where we: 1) create a vector of raster files; 2) use lapply to create raster objects wrapped in terra::src to create a SpatRasterCollection; 3) pass the image collection to the terra::mosaic function.

library(terra)
img <- list.files(getwd(), "tif$", full.names=TRUE)  
  ic <- src(lapply(sarimg, rast))
    r <- mosaic(ic)
Jeffrey Evans
  • 32k
  • 2
  • 48
  • 97