[gdal-dev] BandWriteArray and FlushCache question

Gong, Shawn (Contractor) Shawn.Gong at drdc-rddc.gc.ca
Mon Jan 19 15:44:51 EST 2009


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?


thanks,
Shawn



===================================
RCS_PROC_STEP = 300

src_ds = gdal.Open(src_filename)
self.balanced_ds =
gdal.GetDriverByName("GTiff").CreateCopy(tmp_filename, src_ds, 0)
        
bandobj = self.balanced_ds.GetRasterBand(1)
xsize, ysize = self.balanced_ds.RasterXSize,self.balanced_ds.RasterYSize

output_datatype = gdalnumeric.GDALTypeCodeToNumericTypeCode(
bandobj.DataType )

nblocks = ysize / RCS_PROC_STEP + 1
nlines = RCS_PROC_STEP
        
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()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090119/fd3e3718/attachment.html


More information about the gdal-dev mailing list