[gdal-dev] Reading a single pixel from multiple bands at the
same time in python
Frank Warmerdam
warmerdam at pobox.com
Tue Feb 23 22:25:00 EST 2010
Benjamin Welton wrote:
> Hey,
>
> Iv got a question on whether or not its possible to read a single
> pixel value from multiple bands using one GDAL call in python? The file
> working with is an ENVI BIP file that has a large number of bands
> (around 1000) and im looking for a way to reduce the python overhead by
> only making one single call into the GDAL library. GDALDataset::RasterIO
> seems like it might be the function i need to use but im 100% sure. If
> anyone has any suggestions or hints on whether or not this is possible
> that would be great.
Ben,
You can use the ReadAsArray() method on a gdal.Dataset to read multiple
bands in one call as an array object:
ds = gdal.Open('/home/warmerda/public_html/world.tif')
d = ds.ReadAsArray(0,0,1,1)
print d
[[[11]]
[[10]]
[[50]]]
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the gdal-dev
mailing list