[gdal-dev] Add to PythonGotchas: saving and closing raster datasets
Sean Gillies
sean at mapbox.com
Mon May 5 09:18:34 PDT 2014
Hi Mike,
On 5/3/14, 10:03 PM, Mike Toews wrote:
> Hi,
>
> This seems to be a common gotcha: http://gis.stackexchange.com/q/93212/1872
>
> I've been caught by it before, and I'm certain many others have too.
> This is a gotcha since "WriteArray" doesn't write the array to disk,
> but rather it is written when the dataset object is dereferenced. I've
> drafted up an entry for the wiki, which could be placed before
> "Certain objects contain a Destroy() method, but you should never use
> it".
>
> Furthermore, I'm unsure of the best way to demonstrate how to
> dereference Python objects. The wiki has two different styles:
> obj = None
> or
> del obj
>
> I'm unsure of which is regarded best practice, but encourage
> consistency. Please edit as necessary or reply with suggestions.
>
> -Mike
The thing is that `obj = None` and `del obj` only cause the file to be
written (indirectly) if there are no other references to the Dataset
object. In which case `obj = "Close!"` works just as well ;)
If your code did something like `obj2 = obj` then neither `obj = None`
nor `del obj` will result in the file being closed because the Dataset
object will still have a live reference (obj2).
--
Sean Gillies
sean at mapbox.com
More information about the gdal-dev
mailing list