0

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.

kcw78
  • 7,131
  • 3
  • 12
  • 44
  • It's a swath, so still an irregular grid (without any projection). There are tie-points (GCP's) in the metadata, so you could use those with `gdalwarp` to transform it to a regular grid. But those probably are low accuracy and you'll get better results to use the matching geolocation file (something like MYD03* for example (?), that should contain the latitude/longitude arrays with coordinates for every pixel. – Rutger Kassies Nov 08 '22 at 07:19

1 Answers1

0

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.

HDFEOS.org
  • 185
  • 7