[gdal-dev] Re: HDF subdatasets

Bobby Braswell rob.braswell at unh.edu
Fri Jan 25 09:18:51 EST 2008


Andrea, I'm new to this but the following works for me:

from osgeo import gdal

hdf = gdal.Open('MCD43A4.A2002001.h12v04.005.2007114135144.hdf')
sdsdict = hdf.GetMetadata('SUBDATASETS')
sdslist =[sdsdict[k] for k in sdsdict.keys() if '_NAME' in k]

names=[]
for l in sdslist:
      names.append(l)

hdf = None

sds=[]
for n in names:
	sds.append(gdal.Open(n))



At this point I can inspect the metadata for the subdatasets, e.g.,

sds[0].GetMetadata()
sds[0].RasterCount

Or retreive the image data in the layer corresponding to that  
subdataset, e.g.,

layer = sds[0].ReadAsArray()
type(layer)
dir(layer)
layer.shape


Good luck,
Rob Braswell


On Jan 25, 2008, at 6:44 AM, andrea.pistoni at next.it wrote:

> Hi Rob!
>
> Maybe you can help me. I'm using Gdal.Open() method to open an HDF5  
> file with attributes and Dataset inside.
> I work with C#. The "Open" method opens the file but I cannot see  
> the Raster contained in it and the RasterCount property is 0 (seem  
> such as it don't see the raster).
> Is there a command of GDAL to acces directly to a specific Dataset  
> inside a HDF5 file?
> Using GetMetadata("SUBDATASET") I get the list of Dataset with name,  
> path and dimensions but How can I get the Dataset Matrix? The  
> "ReadRaster" method doesn't work because the Dataset ds has  
> RasterCount equals to zero
> An example of my code is:
> ....
> Dataset ds = Gdal.Open("c:\Test.h5", "c:\plotina.bmp");
> ....
>
> Thank in advance
>
> Andrea
>
> -------------------------------------
>
>
> Bobby Braswell wrote:
>>
>>
>> Hi-
>>
>> Is it possible to access the names of subdatasets in HDF4 files using
>> gdal-python? I can get the SDS names using gdalinfo, but would like
>> to do it from within my code.
>>
>> For example the result of
>>
>> D = gdal.Open('MCD43A4.A2002001.h18v01.005.2007115060137.hdf')
>>
>> produces some dictionaries within D containing metadata information,
>> but I can't find the subdataset names anywhere, e.g.,
>>
>> 'HDF4_EOS:EOS_GRID 
>> :"MCD43A4.A2002001.h18v01.005.2007115060137.hdf":Nadir
>> _Reflectance_Band1'
>>
>> Thanks very much,
>> Rob Braswell
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>>
> Quoted from:  http://www.nabble.com/HDF-subdatasets-tp15049650p15049650.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20080125/323438c7/attachment-0001.html


More information about the gdal-dev mailing list