[gdal-dev] Raster size and ReadAsArray()

Alexander Bruy alexander.bruy at gmail.com
Wed Aug 3 09:35:22 EDT 2011


There is a well-know "problem": reading really large rasters or bands
into memory with DataSource.ReadAsArray() method impossible due
memory limitations. For example, when I try to read one band with
size 53109x29049 I get error:

File "C:\OSGeo4W\apps\Python25\lib\site-packages\osgeo\gdal.py", line
727, in ReadAsArray
    return gdalnumeric.DatasetReadAsArray( self, xoff, yoff, xsize,
ysize, buf_obj )
File "C:\OSGeo4W\apps\Python25\lib\site-packages\osgeo\gdal_array.py",
line 162, in DatasetReadAsArray
    return BandReadAsArray( ds.GetRasterBand(1), xoff, yoff, xsize,
ysize, buf_obj = buf_obj)
File "C:\OSGeo4W\apps\Python25\lib\site-packages\osgeo\gdal_array.py",
line 228, in BandReadAsArray
    ar = numpy.empty([buf_ysize,buf_xsize], dtype = typecode)
ValueError: dimensions too large.

I want to know is it possible to get maximum raster size that can be handled
using ReadAsArray() without errors because I want to implement a fallback
algorithm for large rasters in my tool.

Currently I try to implement it with try-except statement but maybe
there is more
elegant solution?

Alexander Bruy

More information about the gdal-dev mailing list