0

I am able to extract() from rasterstack and wrote a x,y txt file as discussed here How to extract values from rasterstack with xy coordinates?

However, when my I used a big rasterstack, I end up with memory issue.

library(raster)   
r <- raster(nrow=1000, ncol=1500)  
s <- stack( sapply(1:366, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )  
s[1:3]<-NA  
vals<-extract(s,1:ncell(s))  
Warning messages:  
1: In s[1:3] <- NA :  
  Reached total allocation of 1535Mb: see help(memory.size)  
2: In s[1:3] <- NA :  
  Reached total allocation of 1535Mb: see help(memory.size)  
coord<-xyFromCell(s,1:ncell(s))  
combine<-cbind(coord,vals)  
write.table(combine,"xyvalues.txt")  

I would really appreciate any help.
Thanks in advance.

Community
  • 1
  • 1
Eddie
  • 783
  • 4
  • 12
  • 24
  • You have a seriously big number of values to extract. `1500 * 1000 * 366`. Raw in-memory storage space for a vector of this length ( `object.size(1:(1500*1000*366))` ) is `2196000040 bytes`. Which is ~ 2GB. Get more RAM. Or do it in chunks, i.e. one layer at a time. Also `values(s)` might be a bit more efficient for extracting all the values. – Simon O'Hanlon Nov 08 '13 at 10:20
  • @SimonO101, Thanks again. Increase memory limit using memory.limit(25000) solved my problem but end up with a txt file that really huge as predicted(2.7Gb). Total rows are 1,708,882. Fuhh... I need to find ways on how to plot specific row over time. – Eddie Nov 08 '13 at 21:29

0 Answers0