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

pgalpern pgalpern at gmail.com
Thu Jan 5 03:57:47 CET 2012


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