I have recently started a new open-source project that will use gdal extensively, named scikits.eartho.<br><br>The vision is to implement some advanced algorithms and ideas that we develop and work with at the South African Satellite Applications Centre (SAC) for use in Python (SciPy).<br>
<br>I am experiencing some trouble with RasterBand.ReadAsArray.<br><br>My python code:<br><br><div style="margin-left: 40px;">import osgeo.gdal as gdal<br><br>class RasterReaderWriter:<br> def __init__(self, raster):<br>
self.raster = raster<br> self.tileWidth =1024<br> self.tileHeight = 1024<br> self.tileNum = 0 <br> <br> def setTileSize(self, width, height):<br> self.tileWidth =width<br> self.tileHeight = height<br>
<br> def resetIterator(self):<br> self.tileNum = 0<br> <br> def readNextTile(self):<br> tileRaster, offsetX, offsetY, width, height = self.readTile(self.tileNum)<br> self.tileNum = self.tileNum + 1<br>
return tileRaster, offsetX, offsetY, width, height <br> <br> def readTile(self, tileNum):<br> tilesInWidth = self.raster.XSize / self.tileWidth + 1<br> offsetX = tileNum % tilesInWidth * self.tileWidth<br>
offsetY = tileNum / tilesInWidth * self.tileHeight<br> width = min(self.tileWidth, self.raster.XSize - offsetX) <br> height = min(self.tileHeight, self.raster.YSize - offsetY) <br> print offsetX, offsetY, width, height<br>
tileRaster = self.raster.ReadAsArray(offsetX, offsetY, width, height)<br> return tileRaster, offsetX, offsetY, width, height <br><br><br><br><br>reader = RasterReaderWriter(gdal.Open(iFilename).GetRasterBand(1))<br>
print reader.raster.XSize<br>print reader.raster.YSize<br>tile, offsetX, offsetY, width, height = reader.readNextTile()<br></div><br>Before the call to readNextTile() the raster XSize and YSize is correct.<br>After the call the raster seems to have been corrupted as the XSize and YSize have invalid values.<br>
<br>Any help would be appreciated!<br><br>Riaan<br>