Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Here's the problem shown in Python shell:

In [32]: from osgeo import gdal

In [33]: geotiff = '/Users/calvin/work/luc/proj_public/media/GLO
/Users/calvin/work/luc/proj_public/media/GLOBCOVER_L4_200901_200912_V2.3.color.tif
/Users/calvin/work/luc/proj_public/media/GLOBCOVER_L4_200901_200912_V2.3.color_orig.tif
/Users/calvin/work/luc/proj_public/media/GLOBCOVER_L4_200901_200912_V2.3.tif
/Users/calvin/work/luc/proj_public/media/GLOBCOVER_L4_200901_200912_V2.3_CLA_QL.tif

In [33]: geotiff = '/Users/calvin/work/luc/proj_public/media/GLOBCOVER_L4_200901_200912_V2.3.color.tif'

In [34]: src = gdal.Open(geotiff)

In [35]: band = src.GetRasterBand(1)

In [36]: band
Out[36]: <osgeo.gdal.Band; proxy of <Swig Object of type 'GDALRasterBandShadow *' at 0x10632b8f0> >

In [37]: ar = band.ReadAsArray()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/calvin/work/luc/<ipython-input-37-d7dde170464f> in <module>()
----> 1 ar = band.ReadAsArray()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/osgeo/gdal.pyc in ReadAsArray(self, xoff, yoff, win_xsize, win_ysize, buf_xsize, buf_ysize, buf_obj)
    893         return gdalnumeric.BandReadAsArray( self, xoff, yoff,
    894                                             win_xsize, win_ysize,
--> 895                                             buf_xsize, buf_ysize, buf_obj )
    896 
    897     def WriteArray(self, array, xoff=0, yoff=0):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/osgeo/gdal_array.pyc in BandReadAsArray(band, xoff, yoff, win_xsize, win_ysize, buf_xsize, buf_ysize, buf_obj)
    225                                     buf_xsize, buf_ysize, datatype )
    226         ar = numpy.fromstring(band_str,dtype=typecode)
--> 227         ar = numpy.reshape(ar, [buf_ysize,buf_xsize])
    228 
    229         return ar

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in reshape(a, newshape, order)
    169     except AttributeError:
    170         return _wrapit(a, 'reshape', newshape, order=order)
--> 171     return reshape(newshape, order=order)
    172 
    173 

ValueError: total size of new array must be unchanged
share|improve this question
    
Was any solution found? –  najuste Sep 21 '12 at 11:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.