[R-sig-Geo] Properly closing GDAL datasets

Roger Bivand Roger.Bivand at nhh.no
Sat Aug 9 21:25:38 CEST 2014


You need to provide full information from sessionInfo() such as platform 
and rgdal version, the messages displayed when rgdal is loaded, and how 
you installed GDAL. The answer will depend on these, not least because 
recent rgdal versions clean up better than earlier versions.

Roger

On Sat, 9 Aug 2014, Christopher Swingley wrote:

> 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
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list