[Gdal-dev] color table problems

Mario Beauchamp starged at videotron.ca
Fri Jan 21 22:39:50 EST 2005


Hi Frank,

On Fri, 21 Jan 2005 16:24:59 -0500, Frank Warmerdam <fwarmerdam at gmail.com> wrote:

>> def getColorTable(f):
>>     band = gdal.Open(f).GetRasterBand(1)
>
>The problem turns out to be related to reference counting. 
>It turns out that "band" objects don't get a reference to the 
>dataset the way I bound GDAL in Python.  So you need to be
>careful to keep around a reference to the dataset till you are
>done operating on the file.
>
>eg. 
>
>  ds= gdal.Open(f)
>  band = ds.GetRasterBand(1)
>  ... do stuff ...
>
>  ds = None

Thanks. This could explain a lot, since I often use "shortcuts" such as these...
Are there other objects that don't get a reference?

I also often wondered about how to properly close a dataset and make sure everything gets written to
the file before closing. Is that the purpose of the FlushCache() method?

Thanks again.
--
Mario B.
Landsat images (demo):
http://pages.infinit.net/starged/landsat/home.htm



More information about the Gdal-dev mailing list