[R-sig-Geo] Memory management with rasterToPolygons (raster and rgeos)

pgalpern pgalpern at gmail.com
Thu Jan 5 18:11:21 CET 2012


I did some further research into my own question when I twigged to the 
idea that this might be a memory leak with the GEOS library.

It seems likely that is, and has been documented in this forum this 
October past:
https://mailman.stat.ethz.ch/pipermail/r-sig-geo/2011-October/013289.html

As of October there didn't appear to be any real resolution to the 
problem, except - perhaps - to run rgeos under Linux.

Is this the status quo?

Thanks,
Paul

On 04/01/2012 8:57 PM, pgalpern wrote:
> Hello!
>
> Not sure if this is the best place to ask what may ultimately be an 
> rgeos question.
>
> I am running the latest versions of the raster and rgeos packages 
> under 64bit 2.14.1 on Windows 2008R2 Server with 12GB RAM and having 
> some challenges with memory.
>
> I am turning rasters (approx 500 x 1000 cells) into 1500 
> SpatialPolygons, representing each of the feature classes. It works as 
> it should, using rasterToPolygons(x, dissolve=T) but memory overhead 
> is sky high.
>
> For example, a single instance of this function quickly consumes 2-3 
> GB and would probably consume more if other instances were not also 
> running simultaneously.   As a result disk swapping occurs which slows 
> everything down.  Interestingly, the input raster and output 
> SpatialPolygons objects are only megabytes in size.  Running this 
> under 32bit R doesn't seem to help and occasionally results in memory 
> allocation failures.
>
> Finally, deleting the raster and polygons objects when the function is 
> complete and running gc() does not seem to release the memory.  
> Instead the entire R instance needs to be terminated.
>
> Can anyone tell me if this is expected behaviour ... or perhaps 
> suggest a more memory efficient approach.
>
> Thank you,
> Paul
>

-- 
Paul Galpern, PhD Candidate
Natural Resources Institute
70 Dysart Road
University of Manitoba
Winnipeg, Manitoba, Canada R3T 2M6
http://borealscape.ca



More information about the R-sig-Geo mailing list