It works perfectly - many, many thanks Robert.
simon
 

________________________________
De : Robert J. Hijmans <r.hijmans@gmail.com>
À : Simon Chamaillé <s.chamaille@yahoo.fr>
Cc : r-sig-geo@r-project.org
Envoyé le : Mercredi 10 Août 2011 21h11
Objet : Re: [R-sig-Geo] convert Raster object to bigmatrix object


Simon, 

Perhaps the below function works or can get you started.

Best, Robert


library(raster)
library(bigmemory)

raster2bm <- function(x, filename) {  
filename <- trim(filename)
z <- filebacked.big.matrix(ncell(x), nlayers(x), backingfile=filename,descriptorfile=extension(filename, '.desc'))
tr <- blockSize(x)
for (i in 1:tr$n) {
r1 <- cellFromRowCol(x, tr$row[i], 1)
r2 <- cellFromRowCol(x, tr$row[i] + tr$nrows[i] - 1, ncol(x))
z[r1:r2,] <- getValues( x, row=tr$row[i], nrows=tr$nrows[i] )
}
z
}

2011/8/9 Simon Chamaillé <s.chamaille@yahoo.fr>

Hello all,
>
>I would like to perform a kmean analysis on several (big) raster images. I
>thought of using the bigmemory/biganalytics packages, using raster package to
>first do some work on the images, then integrate them in a big.matrix (nrow = nb
>of cells of images, ncol= nb of images), and run the bigkmeans.
>Writing the raster objects as ascii files and then importing them using
>read.big.matrix might work, but it will need another program to remove the
>header (I've got too many images to do it by hand), and sure will involve a lot
>of read/write operation (using getValues to put values straight into a
>big.matrix object doesn't work on my machine as it hits the memory wall...).
>It's sure feasible, but I was wondering if anyone had a better solution/idea. ??
>Giving the popularity that both raster and big* packages are gaining, I trust it
>would be useful to find an easy way to do a raster to bigmatrix conversion.
>
>Best,
>
>simon
>       [[alternative HTML version deleted]]
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo@r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
	[[alternative HTML version deleted]]

