I have a raster layer of vegetation cover (range from 1 to 3). The size of the file totals 60 Mb so it is not big at all. I know this is duplicating other questions, but they have not helped me out.
I tried gc()
, memory.limit()
, etc.
This is the raster file
class : RasterLayer
dimensions : 66861, 126115, 8432175015 (nrow, ncol, ncell)
resolution : 30, 30 (x, y)
extent : -2189805, 1593645, 389625, 2395455 (xmin, xmax, ymin, ymax)
crs : +proj=aea +lat_0=50 +lon_0=-154 +lat_1=55 +lat_2=65 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs
values : 1, 3 (min, max)
I want to do a simple extraction of pixels but it keeps giving me the error:
library(raster)
r = raster("path/raster.tif")
x = r[r == 1]
Error: cannot allocate vector of size 62.8 Gb
I work on a 64bit computer with enough RAM to do this (I thought). I cannot minimize the raster further. How can I tackle this problem?