[R-sig-Geo] changing the data type of a gdal dataset

Alan Swanson alan.swanson at umontana.edu
Fri Nov 20 05:54:42 CET 2009

Dear R gurus,
I have a function that applies various model prediction functions over a 
set of large image files, producing a single output file with the same 
spatial extent.  Due to memory issues, I'm breaking the input and output 
files into tiles.  I have this working except for one small issue 
regarding data types. 

I create a new gdal transient dataset by copying an existing one using:
handle <- GDAL.open(fullnames[1],read.only=T)
tds <- 
putRasterData(tds,t(preds), offset= c(strt[1], 0))
Which works great, except that my output always needs to be floating 
point, but the input may be byte or integer, in which case the output 
dataset retains the format of the input file.  So I either need to 
change the data type of the new file, or create the new file using:
tds <- new("GDALTransientDataset",driver,dims[1],dims[2], type="Float32")

and then copy the spatial reference information from an existing 
dataset.  I can't figure out how to do either of these.  Your help would 
be much appreciated.

More information about the R-sig-Geo mailing list