[R-sig-Geo] raster::crop() can fail when cropped region is too large to process in memory.

Josh O'Brien joshmobrien at gmail.com
Tue Mar 5 17:48:26 CET 2013


Robert Hijmans wrote
> Josh,
> 
> Thanks for reporting this, I will make 'crop' more conservative. The
> easiest way to deal with this (I believe rare) problem is to change the
> default setting of "maxmemory":
> 
> rasterOptions(maxmemory=1e+07)
> 
> After that,
> 
> crop(r, E, filename="smallerRast")
> 
> will likely run without a problem (although I cannot know for sure).
> 
> Robert

Robert,

Thanks! I can confirm that setting maxmemory to 1e7 solves the problem.

I believe that you may want to up n in canProcessInMemory, to n=5 (rather
than n=4).  With a bit of poking around, I found cases in which crop will
fail even when canProcessInMemory(out, 4) --> TRUE, but wherever
canProcessInMemory(out, 5) --> TRUE, the operation succeeds.

Here's an example where crop fails when canProcessInMemory(out, 4) --> TRUE:

r <- raster("bigRast")
E <- extent(c(-179, 179, -89, 69))
crop(r, E, filename="smallerRast") 

In my use case, editing crop() to use canProcessInMemory(out, 5) made
everything run smoothly, whereas one in five or so of cropping operations
were failing when I used the default.

Thanks for all of your work on this remarkable package,

Josh 



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/raster-crop-can-fail-when-cropped-region-is-too-large-to-process-in-memory-tp7582954p7582968.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list