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):

***

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

 }
saveDataset(ds2, "out.tif")
closeDataset(ds2)
closeDataset(ds1)

***

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?

Thanks!

--j


--

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: [EMAIL PROTECTED], Gchat: jgrn307

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to