[R-sig-Geo] Tiled processing...

Jonathan Greenberg greenberg at ucdavis.edu
Thu Oct 30 02:44:51 CET 2008

I've recently got back into using R to perform spatial analyses, and I'm 
trying to figure out how to perform "true" tiled processing, e.g. 
controlled reading of subsets of an input file, performing a function on 
this subset, and writing the output, subset by subset, to an output file 
and, finally, setting up the appropriate "header" info (the metadata).

Using suggestions Tim Keitt and Roger Bivand gave me some years back, I 
wrote this simple code (all it should do is take an elevation geotiff 
and add 1000 to the elevations, writing the output):


ds1 <- GDAL.open("elev.tif")
driver <- new('GDALDriver', 'GTiff')
ds2 <- new('GDALTransientDataset', driver, nrow(ds1), ncol(ds1), type = 
  for (row in nrow(ds1)) {
    x <- getRasterData(ds1, offset = c(row - 1, 0), region = c(1, 
    elevnew <- x+1000
    putRasterData(ds2, elevnew, offset = c(row - 1, 0))

saveDataset(ds2, "out.tif")


Couple of issues/questions:
1) The code doesn't actually seem to work -- I get a tiny, unreadable 
TIFF out of the back of this algorithm -- what is wrong?
2) I'm actually unclear about exactly what this is doing -- am I really 
just creating a large in-memory matrix (ds2) and then writing the entire 
output image out to disk, or is this somehow writing line-by-line?  If 
the former is true, how do I modify this to write within the loop, 
rather than all-at-once?




Jonathan A. Greenberg, PhD
Postdoctoral Scholar
Center for Spatial Technologies and Remote Sensing (CSTARS)
University of California, Davis
One Shields Avenue
The Barn, Room 250N
Davis, CA 95616
Cell: 415-794-5043
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307

More information about the R-sig-Geo mailing list