[gdal-dev] question about ReadAsArray

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Tue Dec 14 16:32:12 EST 2010


Hi all

well, the ReadAsArray function will return a numpy array of dimension 2.
In numpy the array.size() function will return (number_of_lines,
number_of_columns).
The number of lines in the array is the same as the YSize of the
raster in GDAL, and the number of columns is the same as the XSize of
the raster, so it means you are getting the expected result.

;)

2010/12/14 Jorge Arévalo <jorge.arevalo at deimos-space.com>:
> Hi,
>
> On Mon, Dec 13, 2010 at 11:33 PM, Matt Funk <mafunk at nmsu.edu> wrote:
>> Hi,
>>
>> i am a bit new to the gdal library. I am trying to process some geotiff
>> files in python.
>>
>> 1) I am making a call to the ReadAsArray data as such:
>> ...
>> band = ds.GetRasterBand(1)
>> array = band.ReadAsArray(0,0,band.XSize,band.YSize)
>> print array.shape
>> ...
>> which returns: (7191, 8331)
>> Now, what i don't understand is that when i do:
>> ...
>> print 'Size is ',ds.RasterXSize,'x',ds.RasterYSize, 'x',ds.RasterCount
>> ...
>> i get: Size is  8331 x 7191 x 1
>>
>> So does that mean that ReadAsArray returns the an array that has its
>> dimensions flipped?
>>
>
> If I'm not wrong (I'm looking at the code), yes, the Y coord is put
> before the X coord.
>
>
>>
>> 2) Where can i find the documentation for the ReadAsArray fcn?
>>
>
> You can find the function here
> http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/osgeo/gdal.py,
> but the code which does the job is here
> http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/python/osgeo/gdal_array.py,
> and rely on numpy
>
>>
>> thanks
>> matt
>>
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
> Best regards,
>
> --
> Jorge Arévalo
> Internet & Mobilty Division, DEIMOS
> jorge.arevalo at deimos-space.com
> http://mobility.grupodeimos.com/
> http://gis4free.wordpress.com
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
___________________________ ___ __
Ricardo Garcia Silva


More information about the gdal-dev mailing list