1

enter image description here

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)
3

If you want to load a multi-band raster up, don't use raster() function, use brick() or stack() instead. 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)

enter image description here enter image description here

Use write.raster(rotated_raster,'path_/to/file.tif') then for saving the file in your computer.

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.