1

I have just downloaded NDVI imagery from Google Earth Engine. The image was too big so it was divided into about 35 .tif files. Each tile has approximately 950 bands of NDVI values.

I am now trying to stitch the images back together in R. I have tried two different methods:

The first method which uses the raster package is really slow:

library(raster)

f <- list.files(path = "/scratch/MODIS_NDVI_TIFS", pattern = ".tif$", full.names = TRUE)

rl <- lapply(f, raster::brick)

m <- do.call(raster::mosaic, rl)

writeRaster(m,"APL_NDVI_Combined.tif")

The second method I found discussed here which I modified for my use as such:

library(gdalUtils)
library(rgdal)
library(raster)


f <- list.files(path = "/scratch/MODIS_NDVI_TIFS", pattern = ".tif$", full.names = TRUE)


e <- extent(113.338953078, 153.569469029,-43.6345972634, -10.6681857235)

template <- raster(e)
proj4string(template) <- '+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs '

writeRaster(template, file="Combine_NDVI.tif", format="GTiff",overwrite=TRUE)

mosaic_rasters(gdalfile=f,dst_dataset="Combine_NDVI.tif",of="GTiff")

However, I get an error in during the moasic_rasters call which states:

Error in strsplit(gsub(grep(cmd_output, pattern = "Size is ", value = TRUE),  : 
subscript out of bounds
Calls: mosaic_rasters -> gdalinfo
Execution halted

Any idea what is going on here? Are there better suggestions for combining these rasters together?

1
  • The appropriate raster method would be raster::merge(, overlap=FALSE). That should be faster than mosaic. Or try terra::merge Nov 26 '20 at 2:46
1

This Q & A should work, although you may run into memory issues depending on RAM etc

Error while combining multiple partially overlapping rasters into a single raster in R

2
  • What package does mosaicList come from?
    – Douglas
    Nov 28 '20 at 21:53
  • mosaicList is a custom function, detailed earlier in the thread- mainly built on raster Dec 8 '20 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.