Problems converting rasters from float to integer.
I have a large number of rasters ( tiffs) that contain whole number values
between 0 and 100, and NA values. or 0,1,and NA
they are currently in Float format, I am trying to rewrite them as integer
rasters, firstly to save space, and secondly so that I can later read the
values stack of all the rasters into an integer array. using getValues().
To do this I am setting the dataType to INT2U in writeRaster, however when
I read the save file back into R the format is not INT2U but FLT8S
toy example:
v<-c(rep(1.00000,25),rep(0.00000,50),rep(NA,25))
m<-matrix(v,10,10)
r<-raster(m)
dataType(r)
writeRaster(r,"test_int.tif",dataType="INT2U",overwrite=T)
s<-raster("test_int.tif")
dataType(s)
the result I get:
v<-c(rep(1.00000,25),rep(0.00000,50),rep(NA,25)) m<-matrix(v,10,10) r<-raster(m) dataType(r)
[1] "FLT4S"
writeRaster(r,"test_int.tif",dataType="INT2U",overwrite=T)
s<-raster("test_int.tif")
dataType(s)
[1] "FLT8S"
Can you suggest how I ensure the values are stored as integer? Many thanks