I have been trying to extract scientific data layers from MODIS HDF files but without success. Before I have been doing this type of task using Arcpy, but I want the script that I am currently working to be based only in GDAL and not in Arcpy so I can easily share it.
I used GDAL, but it seems that GDAL version in windows does not have support for HDF files (I browsed some forums about it). I tried to open the HDF file using gdal.Open() but it does not return anything, and I am pretty sure that my directory path to the HDF file is correct.
Then I tried pyHDF. So this packages allowed me to extract the scientific layers as 2D array, but I have a problem how to save it as GeoTIFF file. I am aware that for me to save a 2D array to a GeoTIFF file I need some reference, such as projection and raster properties, just like the GetGeoTransform() module in GDAL. In this step, I am not sure how to extract that same kind of information using pyHDF.
[GIS] extract scientific layers from MODIS HDF Dataeset using Python GDAL
gdalhdfmodispython
Best Answer
Here is my code I use to convert all HDFs in a folder to GeoTIFF via GDAL (OSGEO4w) in Windows when working with SST data. Remember to use the OSGEO4W version to get hdf support.
for %A in ("C:\temp\*.hdf") do
Loop through all files in the folder with .hdf extension.gdal_translate -of GTiff
Convert all files in the selected folder to GTiff.-a_srs
Set the WGS 1984 projection to all the Gtiffs.-a_ullr
Set the bounds of all the Gtiffs.-co
Compress all the Gtiffs.-sds
Convert all files in the hdf, subdataset.TIP
Use
–ot Float32
for floating point we are in Integer.