TransWikia.com

Using R, how do I rotate a GeoTiff file with multiple bands and save it?

Geographic Information Systems Asked on January 30, 2021

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)

One Answer

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.

Answered by aldo_tapia on January 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP