[R-sig-Geo] Write a new raster brick calculated from the other two raster stacks

Arc RS hyinhe at gmail.com
Wed Apr 8 18:49:10 CEST 2015


Hi, I got stuck in output a raster stack calculated from the other two
raster stacks. The input and output rasters have same dimentions
(nrow*ncol*nlayer).

input raster stack 1: ras1
input raster stack 2: ras2
output raster: outras

The function I used for stacks calculation is: func

Here are my codes:

#####make blocks#######
tr <- blockSize(ras1)

###check the block info###
> str(tr)
List of 3
 $ row  : num [1:4] 1 191 381 571
 $ nrows: num [1:4] 190 190 190 189
 $ n    : num 4

####define output raster###
outras <- brick(ras1)
outras <- writeStart(outras , filename='output.tif',  overwrite=TRUE)

####start calculation and output###
for (i in 1:tr$n)
{
  rasvl1  <- getValues(ras1,tr$row[i],tr$nrows[i])
  rasvl2  <- getValues(ras2,tr$row[i],tr$nrows[i])
  ok       <- func(rasvl1, rasvl2)
  outras  <- writeValues(x=outras, v=ok,start=tr$row[i])
}
outras <- writeStop(outras )

#####

But I got an error message 'Error in (function (classes, fdef, mtable) :
 unable to find an inherited method for function ‘getValues’ for signature
‘"matrix", "numeric", "numeric"’

I checked the output tiff file, and I found only the first block was
written. The rest three blocks are missing.

Any ideas?

Thanks in advance!
Eric

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list