[Gdal-dev] Python Problem

Norman Vine nhv at cape.com
Fri May 19 14:12:05 EDT 2006


Christopher Condit writes:

> Here's a better piece of code illustrating the problem I'm having:
> 
> bands=[]
> for timeSlice in range(60):
>     file = "C:\\develop\\brewin\\vel-%i.tif" % timeSlice
>     dataset = gdal.Open( file, GA_ReadOnly )
>     bands.append(dataset.GetRasterBand(1))
> for iter in range(len(bands)):    
>     #The following line prints correctly (720x330)
>     print "Dimension: (%i, %i)" % (bands[iter].XSize, bands[iter].YSize)
>     #The following line throws 
>     #TypeError: Access window out of range in RasterIO().  Requested
>     #(0,0) of size 720x1 on raster of 65x16. 
>     line = bands[iter].ReadAsArray( 0, 0, bands[iter].XSize, 1 )   
> 
> Thanks for any help,


## adapted from $GDAL/pymod/samples/rel.py  
## untested

bands=[]
for timeSlice in range(60):
    file = "C:\\develop\\brewin\\vel-%i.tif" % timeSlice
    dataset = gdal.Open( file, GA_ReadOnly )
    bands.append(dataset.GetRasterBand(1))

for band in bands:    
    print "Dimension: (%i, %i)" % (band.XSize, band.YSize)
    for i in range( band.YSize - 1):
      line = band.ReadAsArray(0, i + 1, band.XSize, 1, band.XSize, 1)[0]

HTH

Norman



More information about the Gdal-dev mailing list