How to read location coordinates of MODIS HDF file with Python GDAL?

493 views Asked by At

I am trying to read a MODIS HDF file with Python. I have used GDAL and pyhdf libraries. However, I am unsure why GDAL is unable to read location coordinates whereas pyhdf can read the same easily. Following is the simple python code.

from pyhdf import SD
from osgeo import gdal

filename = 'MYD04_3K.A2016001.0310.061.2018059005952.hdf'

gdal_ds= gdal.Open(filename)
hdf_ds = SD.SD(filename)
print (hdf_ds.datasets())

for path, desc in file.GetSubDatasets():
    print(desc)

The output for pyhdf is as follows:

{'Longitude': (('Cell_Along_Swath:mod04', 'Cell_Across_Swath:mod04'), (676, 451), 5, 0), 'Latitude': (('Cell_Along_Swath:mod04', 'Cell_Across_Swath:mod04'), (676, 451), 5, 1), 'Scan_Start_Time': (('Cell_Along_Swath:mod04', 'Cell_Across_Swath:mod04'), (676, 451), 6, 2), 'Solar_Zenith': (('Cell_Along_Swath:mod04', 'Cell_Across_Swath:mod04'),

The output for GDAL is as follows:

[676x451] Solar_Zenith mod04 (16-bit integer)
[676x451] Solar_Azimuth mod04 (16-bit integer)

I would like to learn why GDAL is unable to read location coordinates here. Is there anything I'm missing? How can I extract the location information by using GDAL library? My main aim eventually is to plot a specific variable from HDF file on map.

1

There are 1 answers

0
HDFEOS.org On

Check lines from 1952 to 1954 in

https://github.com/OSGeo/gdal/blob/master/frmts/hdf4/hdf4imagedataset.cpp

pyhdf doesn't look for lat/lon datasets. It's a simple wrapper for HDF4 library.