[gdal-dev] ReadAsArray misbehaving...
Riaan van den Dool
riaanvddool at gmail.com
Fri Sep 3 07:45:00 EDT 2010
Thanks for the suggestion.
I have tried:
tileRaster = self.raster.ReadAsArray(xoff=offsetX, yoff=offsetY,
win_xsize=width, win_ysize=height)
and
tileRaster = self.raster.ReadAsArray(xoff=offsetX, yoff=offsetY,
buf_xsize=width, buf_ysize=height)
but the result is something like:
(array([], shape=(0, 1024), dtype=float32), 0, 0, 1024, 0)
Riaan
On Fri, Sep 3, 2010 at 1:33 PM, Chaitanya kumar CH
<chaitanya.ch at gmail.com>wrote:
> Riaan,
>
> Try calling the method as below
> tileRaster = self.raster.ReadAsArray(xoff=offsetX, yoff=offsetY,
> xsize=width, ysize=height)
>
> On Fri, Sep 3, 2010 at 4:09 PM, Riaan van den Dool <riaanvddool at gmail.com>wrote:
>
>> 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
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
>
>
> --
> Best regards,
> Chaitanya kumar CH.
> /tʃaɪθənjə/ /kʊmɑr/
> +91-9494447584
> 17.2416N 80.1426E
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100903/b3fcab39/attachment.html
More information about the gdal-dev
mailing list