[R-sig-Geo] setValues for a RasterStack

Jonathan Greenberg jgrn at illinois.edu
Wed Jun 13 19:30:24 CEST 2012


* edit -- the title of this post should have been "setValues with a
RasterBrick".

On Wed, Jun 13, 2012 at 12:23 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
> 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
>
>> inMemory(x)
> 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
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Department of Geography and Geographic Information Science
> University of Illinois at Urbana-Champaign
> 607 South Mathews Avenue, MC 150
> Urbana, IL 61801
> Phone: 415-763-5476
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
> http://www.geog.illinois.edu/people/JonathanGreenberg.html



-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 415-763-5476
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
http://www.geog.illinois.edu/people/JonathanGreenberg.html



More information about the R-sig-Geo mailing list