[R-sig-Geo] Problems converting rasters from float to integer.
Roger@Biv@nd @ending from nhh@no
Fri Aug 24 10:05:25 CEST 2018
Thanks, Mike. I agree that the lower level interface in rgdal is flexible enough, but as you say non-trivial. Nevil: could you please provide a small reproducible example to point people in the right direction?
Norwegian School of Economics
Fra: Michael Sumner
Sendt: fredag 24. august, 09.14
Emne: Re: [R-sig-Geo] Problems converting rasters from float to integer.
Til: nevil amos
Kopi: r-sig-geo using r-project.org
I'm pretty sure readGDAL from rgdal (that raster uses) will keep as integers, so you can build an empty raster and copy the values over. But will need to derive from the rgdal version to catch all the metadata (structure, extent, and crs). I think it's doable and will try later. There are other options but nothing trivial afaik. Cheers, Mike On Fri, 24 Aug 2018, 16:45 nevil amos wrote: > 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 m r dataType(r) > writeRaster(r,"test_int.tif",dataType="INT2U",overwrite=T) > s dataType(s) > > the result I get: > > > v > m > r > dataType(r) >  "FLT4S" > > writeRaster(r,"test_int.tif",dataType="INT2U",overwrite=T) > > s > dataType(s) >  "FLT8S" > > > > > Can you suggest how I ensure the values are stored as integer? > > Many thanks > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo using r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Dr. Michael Sumner Software and Database Engineer Australian Antarctic Division 203 Channel Highway Kingston Tasmania 7050 Australia [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo using r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[[alternative HTML version deleted]]
More information about the R-sig-Geo