[gdal-dev] BandWriteArray and FlushCache question

Frank Warmerdam warmerdam at pobox.com
Mon Jan 19 16:02:53 EST 2009


Gong, Shawn (Contractor) wrote:
> hi list,
> 
> I recently upgraded to gdal 1.6.0 and found that one Python function 
> that used to work in 1.4.4 no longer works.
> 
> The purpose of function was to read in a band, perform matrix 
> manipulation (in this case, subtract a baseline) and resave.
> 
> The error that I am getting is that in the new dataset the last hundreds 
> of lines DN are written zero. If I take out the last line 
> “self.balanced_ds.FlushCache()” then the entire dataset is written as 
> zeros.  None of errors would happen in gdal 1.4.4.
> 
> Is there any changes in gdal 1.6.0 w.r.t. FlushCache() ?  What is the 
> right way to perform this?
...
> for block in range( nblocks ):
> 
>     first_line = RCS_PROC_STEP*block
> 
>     if block == nblocks - 1:
> 
>         nlines = ysize - first_line
> 
>           
> 
>     datablock = gdalnumeric.BandReadAsArray( bandobj, 0, first_line, 
> xsize, nlines )
> 
>     datablock = datablock - baseline
> 
>     gdalnumeric.BandWriteArray( bandobj, 
> datablock.astype(gdalnumeric.Int16), 0, first_line )
> 
> bandobj.FlushCache()
> 
> self.balanced_ds.FlushCache()

Shawn,

I'm not sure of any reason the script shouldn't work properly.  But I
will note that aspects of the TIFF file are only written out when the
file is closed.  You may find it helpful to do "self.balanced_ds = None"
at the end so that python will release the dataset and it can be closed.

I'm not sure of what environment you are running your script in.  Normally
at script end this would happen anyways.

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