[FWTools] How to read an ASTER hdf image into python w/ GDAL

Frank Warmerdam warmerdam at pobox.com
Wed Feb 6 11:24:33 EST 2008

Simon J. Hook wrote:
> Hi,
> Unfortunately no one has responded to this post. Just to let you know I 
> really hope that someone will!!! -- Frank?


Sorry - my installation seems broken in a number of regards and it is hard
for me to try this.  In theory you would just do something like:

import gdalnumeric

x = gdalnumeric.LoadFile('utm.tif')

This gives you a numpy array.

The trick with ASTER data is that the actual data is presumably as
subdatasets.  You could just do a gdalinfo to get a list of subdatasets and
manually enter them in your script.  Or if you need to automate things you
would have to do something more involved like (without testing!):

import gdal
import gdalnumeric

ds = gdal.Open('youraster.hdf')
sds_md = ds.GetMetadata('SUBDATASETS')

for key in (umm ... well I forget how to get key/value's from a dictionary just 
   sds_name = sds_md[key]

   x = gdalnumeric.LoadFile(sds_name)

Hmm, this is a pretty rough approximation!

Good luck,
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    | President OSGeo, http://osgeo.org

More information about the FWTools mailing list