[R-sig-Geo] Properly closing GDAL datasets

Christopher Swingley cswingle at swingleydev.com
Sat Aug 9 20:22:01 CEST 2014


Greetings!

I'm trying to figure out the proper way to close GDAL datasets in a
long-running script.  I think the issue is in this block of code
(versions of which run hundreds of times during the run of the
script):

raster <- readGDAL(tiffs[1], band=1)
raster$band1 <- best_threshold
writeGDAL(raster, fname = output_filename_rpart_best_threshold, driver
= 'GTiff',
                type = 'Int16', mvFlag = 32767,
                options = c('COMPRESS=LZW','INTERLEAVE=BAND'))

I'm reading in band 1 of a raster, populating it with new data, then
dumping it back out elsewhere.  But when this operation finishes,
there's a filehandle open to what looks like a temporary raster in the
/tmp/Rtmp..../ directory, even though the temporary directory is
empty.

I've tried 'rm(raster)' (which doesn't seem to do anything) and
'GDAL.close(raster)', which gives an error that there's no "handle"
slot in a SpatialGridDataFrame.

How does one properly clean up after a readGDAL / writeGDAL operation?
 Or do I need to perform this step differently?

Thanks!

Chris
-- 
Christopher Swingley
Fairbanks, Alaska
http://swingleydev.com/
cswingle at swingleydev.com



More information about the R-sig-Geo mailing list