Skip to content

R array to TIF

2 messages · Christopher Swingley

#
Greetings!

I'm reading in a bunch of TIF images that all have the same extent
using rgdal::readGDAL, and then aggregating the stack of $band1 data
by applying a function to the vector of image data at each pixel.  The
result is an R array.  I want to write out this array as a TIF image
with the same parameters (rows, columns, bounding box, projection,
etc.), but I haven't found the trick to creating a
SpatialGridDataFrame so I can use writeGDAL.  I'm also curious about
how one might change the data type (Byte, Int16, etc.) and nodata
value when dumping it out.

Thanks!

Chris
#
Oops.  I apparently didn't try the simplest thing:

raster <- readGDAL(path) # a 1000 x 1000 raster
raster$band1 <- array(data = 1, dim = 1000000)
writeGDAL(raster, fname = '/tmp/foo.tif', driver = 'GTiff', type =
'Byte', mvFlag = 255)

Cheers,

Chris