[R-sig-Geo] Converting array into raster brick
Robert J. Hijmans
r.hijmans at gmail.com
Thu Dec 16 23:15:58 CET 2010
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
>
More information about the R-sig-Geo
mailing list