[R-sig-Geo] Converting array into raster brick

Agustin Lobo alobolistas at gmail.com
Sun Dec 19 12:20:06 CET 2010


Robert,

Converting from a regular 3D array to brick is probably going to be
quite a  common operation,
perhaps you could consider a simpler syntax in the future, i,e:

r = as.brick(x)

where x would be a 3D array?

Agus

2010/12/16 Robert J. Hijmans <r.hijmans at gmail.com>:
> Christian,
>
> Could be quicker if you make a matrix out of the array (or, if
> possible, avoid the array in the first place). See below
>
> library(raster)
>
> # create an array
> m <- matrix(1:100, ncol=10, byrow=TRUE)
> a <- array(list(m, m, m, m, m))
>
> # empty RasterBrick
> x <- brick(ncol=10, nrow=10)
>
> # make matrix from array
> v <- sapply(a, function(x) as.vector(t(x)))
>
> x <- setValues(x, v)
> plot(x)
>
>
> Best, Robert
>
> On Thu, Dec 16, 2010 at 12:26 PM,  <christian.kamenik at giub.unibe.ch> wrote:
>> Dear all,
>>
>> I needed to convert an array into a RasterBrick object. The output did not
>> need to be written to memory, as assessed by canProcessInMemory(). The only
>> way to put the data into the RasterBrick that worked for me was layer by
>> layer:
>>
>> for (l in 1:nlayers(x)) x
>> <-setValues(x,values=as.vector(t(xx[,,l])),layer=l)
>>
>> This was quite complicated and slow. So I am wondering if there is a better
>> way of doing this.
>>
>> Many thanks, Christian
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list