[gdal-dev] ReadAsArray misbehaving...

Riaan van den Dool riaanvddool at gmail.com
Fri Sep 3 06:39:09 EDT 2010


I have recently started a new open-source project that will use gdal
extensively, named scikits.eartho.

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).

I am experiencing some trouble with RasterBand.ReadAsArray.

My python code:

import osgeo.gdal as gdal

class RasterReaderWriter:
    def __init__(self,  raster):
        self.raster = raster
        self.tileWidth =1024
        self.tileHeight = 1024
        self.tileNum = 0

    def setTileSize(self,  width,  height):
        self.tileWidth =width
        self.tileHeight = height

    def resetIterator(self):
        self.tileNum = 0

    def readNextTile(self):
        tileRaster,  offsetX,  offsetY,  width,  height  =
self.readTile(self.tileNum)
        self.tileNum = self.tileNum + 1
        return tileRaster,  offsetX,  offsetY,  width,  height

    def readTile(self,  tileNum):
        tilesInWidth = self.raster.XSize / self.tileWidth + 1
        offsetX = tileNum % tilesInWidth * self.tileWidth
        offsetY = tileNum / tilesInWidth * self.tileHeight
        width = min(self.tileWidth,  self.raster.XSize - offsetX)
        height = min(self.tileHeight,  self.raster.YSize - offsetY)
        print offsetX,  offsetY,  width,  height
        tileRaster = self.raster.ReadAsArray(offsetX,  offsetY, width,
height)
        return tileRaster,  offsetX,  offsetY,  width,  height




reader = RasterReaderWriter(gdal.Open(iFilename).GetRasterBand(1))
print reader.raster.XSize
print reader.raster.YSize
tile, offsetX, offsetY, width, height = reader.readNextTile()

Before the call to readNextTile() the raster XSize and YSize is correct.
After the call the raster seems to have been corrupted as the XSize and
YSize have invalid values.

Any help would be appreciated!

Riaan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100903/81ddabb4/attachment.html


More information about the gdal-dev mailing list