Question

I'm trying to reclassify a RasterLayer to turn all 0's to NA. I've tried:

  1. Reclassify:

    con1RC<-reclassify(con2, matrix(c(0, 0, NA))
    

    ERROR: cannot allocate vector of size 160.1 Mb

  2. Subs:

     con1Sub<-subs(con2, df, by=1, which=2)
    

    ERROR: error in evaluating the argument 'x' in selecting a method for function 'as.matrix'

  3. Replace NA:

    con1Sub<-con2[is.na(con2)]<-0'
    

    ERROR: cannot allocate vector of size 160.1 Mb

    con2
class       : RasterLayer 
dimensions  : 5533, 3792, 20981136  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 242505, 356265, 4234635, 4400625  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=18 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
data source : G:\Projects\DC\Imagery\Landsat\Classification\Working\confused2_rc_8class.img 
names       : confused2_rc_8class 
values      : 0, 8  (min, max)

I'm using R3.0.0. Windows 7 enterprise, 32 bit. I know memory can be an issue but haven't seen any direction on how to change in windows. I've also used in this code:

memory.size(max=FALSE)
memory.limit(size=NA)

I'll try these on a 64-bit computer too.

Anyone know what's happening with this machine, or can recommend a way to get one of these functions to work?
I'm not calling any matrix with method 2 (just a data.frame), so not sure what this means either.

Was it helpful?

Solution

This is not correct:

matrix(c(0, 0, NA)) 

instead, try

con1RC<-reclassify(con2, cbind(0, NA) )

If you still get out of memory problems, first set some options:

rasterOptions(chunksize=1e+06, maxmemory=1e+07)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top