Skip to content
Prev 19338 / 29559 Next

writeRaster to TIF changes raster maximum value

Guillaume,

This indeed happens because of NA value handling problems.  The native
raster format uses 255 as the NA value for Byte files. That probably
needs to change. You write such a file because you crop a large area
and a temporary file is written. There are work arounds, see below,
but i will ponder changes to the package that will makes these
unnecessary.

The most direct way to avoid this is to do
library(raster)
r = raster('L71015027_02720000730_B10_full.tif')
e =extent( 457785, 577605, 5147085, 5255925)
x = crop(r, e, 'abc.tif', datatype='INT2S', overwrite=TRUE)


Alternatively,

y = crop(r, e)
NAvalue(x) = 0
y <- writeRaster(y, 'abcd.tif', datatype='INT2S', overwrite=TRUE)

Robert
On Mon, Sep 16, 2013 at 1:58 PM, <Guillaume.Drolet at mrn.gouv.qc.ca> wrote: