Ben, Another alternative a little bit more flexible is to use ReadRaster() specifying your query window (1x1 or more), the automatic data type conversion and the list of bands you are querying from. I guess it wrapper RasterIO directly.
Note that the resulting buffer will be binary, not a numpy Array as in ReadAsArray(), but that is easy to convert using numpy.fromstring(). Regards, Ivan > -------Original Message------- > From: Frank Warmerdam <[email protected]> > To: Benjamin Welton <[email protected]> > Cc: [email protected] > Subject: Re: [gdal-dev] Reading a single pixel from multiple bands at the > same time in python > Sent: Feb 23 '10 22:25 > > 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, [email protected] > light and sound - activate the windows | http://pobox.com/~warmerdam > and watch the world go round - Rush | Geospatial Programmer for Rent > > _______________________________________________ > gdal-dev mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/gdal-dev > _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
