When opened in ArcGIS, the raster correctly unfolds 12 bands, but when I try to open it with GDAL through Python, it appears as a raster that has zero bands.

Here is the code:

import gdal
from gdalconst import *
dataset = gdal.Open( filename, GA_ReadOnly )
print ("Format: ",dataset.GetDriver().ShortName)
print ("Projection: ",dataset.GetProjection())
print ("Bands:", dataset.RasterCount)

And here is the output:

('Format: ', 'HDF4')
('Projection: ', '')
('Bands:', 0)

As you can see, the projection is reported as empty, and the number of bands as zero. The raster format is HD4 or HDF. You can easily download a similar raster from this FTP site: ftp://ladsweb.nascom.nasa.gov/allData/5/MOD11A1/2012/193/

Do you have any idea about this issue?


HDF uses subdatasets.
Use dataset.GetSubDatasets() for a list of tuples (name, description), and use gdal.Open() on one of the names, for example:

subdataset = gdal.Open(dataset.GetSubDatasets()[0][0])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.