Opened 15 years ago
Closed 14 years ago
#2658 closed defect (fixed)
gdal_array.BandReadAsArray() takes bogus parameter
Reported by: | dron | Owned by: | hobu |
---|---|---|---|
Priority: | normal | Milestone: | 1.7.0 |
Component: | PythonBindings | Version: | svn-trunk |
Severity: | normal | Keywords: | |
Cc: | hobu, warmerdam, antonio |
Description
gdal_array.BandReadAsArray() function is defined as
def BandReadAsArray( band, xoff, yoff, win_xsize, win_ysize, buf_xsize=None, buf_ysize=None, buf_obj=None ): """Pure python implementation of reading a chunk of a GDAL file into a numpy array. Used by the gdal.Band.ReadaAsArray method."""
See http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/osgeo/gdal_array.py#L110
What is a purpose of the 'buf_obj' parameter? Actually ,it is not used at all, just created if _not_ None (losing the passed value) and then being lost itself (http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/osgeo/gdal_array.py#L134)
if buf_obj is not None: buf_obj = numpy.zeros( shape, typecode ) band_str = band.ReadRaster( xoff, yoff, win_xsize, win_ysize, buf_xsize, buf_ysize, datatype ) ar = numpy.fromstring(band_str,dtype=typecode) ar = numpy.reshape(ar, [buf_ysize,buf_xsize]) return ar
Compare it with the original implementation where that parameter was used and had perfect sense (http://trac.osgeo.org/gdal/browser/trunk/gdal/pymod/gdalnumeric.py#L177):
if buf_obj is None: buf_obj = zeros( shape, typecode ) return _gdal.GDALReadRaster( band._o, xoff, yoff, win_xsize, win_ysize, buf_xsize, buf_ysize, datatype, buf_obj )
I think we should restore the original meaning of this parameter.
Change History (2)
comment:1 by , 15 years ago
Cc: | added |
---|
comment:2 by , 14 years ago
Milestone: | → 1.7.0 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
The fix required quite a few changes in the gdal_array module (I swig'ified it, removed swig/python/extensions/numpydataset.cpp which was unused, etc..). Testing by others appreciated.