I am trying to mosaic multiple multi band datasets into a single large multi band raster in R.I tried to do it with this code but it returns a single band image.
library(sp)
library(raster)
library(rgdal)
setwd("C:\\Projects\\Rice-fallow_4_states\\Bihar\\S1")
x <- list.files(".\\", pattern='tif$',
full.names = TRUE) # list all the rasters
X1<- as.list(x)
allrasters1 <- lapply(X1, raster)
x.mosaic <- do.call(merge,allrasters1)
names(x.mosaic)
x.mosaic
plot(x.mosaic)
When you load rasters in R using
raster(), it only loads one layer of the image. If you want to load the entire multi-band image, use eitherstack()orbrick(). I believebrick()is the most correct one for images with multiple bands, but I don't deal with those often, so I have yet to find a meaningful difference between that andstack().