Skip to content
Prev 15314 / 29559 Next

setValues for a RasterStack

R-sig-geo'ers:

I'm trying to use setValues to replace values of a layer in a
RasterBrick, but I'm getting the following error:

Error in setValues(x, values[startidx[i]:endidx[i]], layer = i) :
  you can only setValues for a single layer if all values are in
memory. But values could not be loaded

The "empty" raster brick (note the "values" is none) is on disk:

class       : RasterBrick
dimensions  : 319, 10853, 3462107, 6  (nrow, ncol, ncell, nlayers)
resolution  : 2, 2  (x, y)
extent      : 748005.1, 769711.1, 4307056, 4307694  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0
values      : none
layer names : layer.1, layer.2, layer.3, layer.4, layer.5, layer.6
FALSE

"values" is a "squashed" vector (BSQ) of all values I wish to write to
the RasterBrick of length ncell(x) * nlayers(x), i is 1:nlayers(x),
and startidx and endidx are the start/stop points for this vector for
each band i:

startidx:
[1]        1  3462108  6924215 10386322 13848429 17310536
endidx:
[1]  3462107  6924214 10386321 13848428 17310535 20772642

I'm trying to setValues(x) one band at a time:

for(i in 1:nlayers(x))
{
	out <- setValues(x,values[startidx[i]:endidx[i]],layer=i)
}

What am I doing wrong?  Does setValues ONLY work if inMemory(x)==TRUE?  Thanks!

--j