[R-sig-Geo] Set output data type for projectRaster

Ned Horning horning at amnh.org
Wed Jul 8 02:32:57 CEST 2015

Hi all -

I am trying to project a raster using the projectRaster() function from 
the raster package and would like the data type for the output image to 
be the same as the data type of the input image (INT2U Landsat 8 image 
stack). For some reason I get an output data type of FLT8S, even when I 
set the resampling method to "ngb". I created some sample code to 
recreate the problem.
# create a new (not projected) RasterLayer with cellnumbers as values
r <- raster(xmn=-110, xmx=-90, ymn=40, ymx=60, ncols=40, nrows=40)
r <- setValues(r, 1:ncell(r))
dataType(r)  <- "INT2U"
# proj.4 projection description
newproj <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84"
pr1 <- projectRaster(r, crs=newproj, res=20000)
pr2 <- projectRaster(r, crs=newproj, res=20000, method="ngb", 
filename="test.tif", dataType="INT2U", format='GTiff', overwrite=TRUE)
In this example the data types are
r is INT2U
pr1 is FLT4S
pr2 is FLT8S

but I want the data type for pr2 to be "INT2U".

Is there any way to select the output data type for an image created 
using projectRaster()?

I'm using R version 3.2.1 and version 2.3-40 of the raster package.

All the best,


More information about the R-sig-Geo mailing list