[Gdal-dev] color table problems

Frank Warmerdam fwarmerdam at gmail.com
Fri Jan 21 16:24:59 EST 2005


On Wed, 19 Jan 2005 18:08:10 -0500, Mario Beauchamp
<starged at videotron.ca> wrote:
> Hi all,
> 
> I'm trying to assign a ColorTable to a VRT in OpenEV using vrtutils.VRTDatasetConstructor(). The
> AddSimpleBand method needs "ColorInterp" and "colortable" so to get it from the source file, I have:
> 
> def getColorTable(f):
>     band = gdal.Open(f).GetRasterBand(1)

Mario, 

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

At the point there are no references to a GDAL dataset it gets
closed.  Operating on objects from a closed dataset results in
disaster sooner or later. 

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Gdal-dev mailing list