[gdal-dev] Re: GDAL WriteArray Memory Error (Python)

hairymapper tom.holderness at ncl.ac.uk
Mon Jan 17 06:46:11 EST 2011


Solved. The error in my previous post occurs because of the way
gdal_array.BandWriteArray() tries to catch unknown datatype errors.

If gdal.BandWriteArray() receives an numpy array with an unrecognized data
type it defaults to using numpy.float64 data type for the output (presumably
in the hope that by using such a large data type no data will be lost in the
output). However, my Windows box can't create such large arrays of float64
type, thus creating a memory error (works fine in Ubuntu). I've included a
code snippet from the function below, showing the definition of this. 

This is what was happening for me due to a difference in the definition of
"byte" data type in Numpy and GDAL:
nump.byte = 8bit integer, gdal.GDT_Byte = 8bit un-signed integer. I fixed by
manually specifying numpy  numpy.dtype('u1').
GDAL wasn't getting the expected datatype and was faling back to
numpy.float64.

# snippet from gdal_array.py
# \osgeo\gdal_array.py bandwritearray()
...
 # if we receive some odd type, like int64, try casting to a very
    # generic type we do support (#2285)
    if not datatype:
        gdal.Debug( 'gdal_array', 'force array to float64' )
        array = array.astype( numpy.float64 )
        datatype = NumericTypeCodeToGDALTypeCode( array.dtype.type )
...
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/GDAL-WriteArray-Memory-Error-Python-tp5921724p5931519.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list