My existing code (see below) only reads and rotates one band but I want all 360 of my bands to rotate.
library(raster) your_raster <- raster("path/to/raster.tif") rotated_raster <- rotate(your_raster)
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
If you want to load a multi-band raster up, don't use
raster() function, use
raster() only opens single-band rasters, even from a multi-band raster (you can set the band you want to open).
Rotate works with multi-band rasters, so you'll be fine after opening the file:
r <- raster(nrow=18, ncol=36) m <- matrix(1:ncell(r), nrow=18) values(r) <- as.vector(t(m)) extent(r) <- extent(0, 360, -90, 90) s <- stack(r,r,r) rr <- rotate(s) plot(s) plot(rr)
write.raster(rotated_raster,'path_/to/file.tif') then for saving the file in your computer.