I have sf data with single point geometries (points
) and a 23,000 x 18,000 elevation RasterLayer with a single band, loaded from a geotiff (elev
). They have the same CRS. I want to extract the elevation values to the points.
When I try running extract(elev, points)
, since my raster is very large I get:
Error: cannot allocate vector of size 3.1 Gb
I followed advice here R - multicore approach to extract raster values using spatial points and tried to parallelize, but I only have a single raster, so chances are the work won't get divided. Still I try the following:
library(snowfall)
sfInit(parallel=TRUE, cpus=parallel:::detectCores()-1)
sfLibrary(raster)
sfLibrary(sp)
# Run parallelized 'extract' function and stop cluster
e.df <- sfSapply(elev, raster::extract, y=points)
sfStop()
I get the same result:
Error: cannot allocate vector of size 3.1 Gb
All the examples I've found so far, such as the above, store multiple rasters in a list. How do I parallelize extraction from a single raster like this? Or is there a way to make use of sparse matrices and memory management as noted here?
I'm on Windows 10 running RStudio 1.1.419 (64 bit). 8GB RAM. Intel Core i5-6200U CPU @ 2.3GHz 2.4GHz