[gdal-dev] Raster size and ReadAsArray()

Antonio Valentino antonio.valentino at tiscali.it
Wed Aug 3 10:39:25 EDT 2011

Hi Alexander,

Il 03/08/2011 15:35, Alexander Bruy ha scritto:
> Hi,
> 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:


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

In my experience using too large chunks of memory can cause,
paradoxically, slowdowns.
My suggestion is to define a reasonable maximum size for arrays in your
application/library and switch to the "fallback algorithm for large
rasters" every time that MAX_SIZE is exceeded, even if using ReadAsArray
still works.

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

IMHO using try-except *is* elegant and perfectly in line with python's

best regards

Antonio Valentino

More information about the gdal-dev mailing list