4

I am working with MODIS .hdf grid files and am looking for some help on exporting specific files from the .hdf. There are 200+ .hdf's and I need to extract the 0, 1, 2, and 11 (NDVI, EVI, quality, and reliability) layers, ideally to .img's and with the nomenclature either intact or editable. Does anyone have a quick way to pull this off, either in ArcGIS, Grass, or QGIS?

2

To convert a HDF subdataset to a GeoTIFF, you can:

gdal_translate HDF5:"your_input.hdf"://SUBDATASET_NAME output.tif 

If you need to check the subdataset names, then:

gdalinfo your_input.HDF 
1

The Translate tool in QGIS will allow you to batch convert from .hdf to .img. However you will not be able to perform this on the specific channels (0,1,2,11). You could do this with FW_Tools, using the gdal_translate exe. Within gdal_translate you can identify -b for the bands to use.

 gdal_translate -of HFA -b 0 1 2 11 c:\temp\source.hdf c:\temp\output.img

Something like this would work. You could script this, or make a batch file.

  • Thanks for the help. The following script seems to work in FW_tools, but not exactly as I had hoped: gdal_translate -of HFA -sds e:\source.hdf e:\output.img Do you have any suggestions as to how to select specific subdatasets (specifically 0, 1, 2, 11 as before)? When trying to do this by adding the numbers after -sds fw_tools fails with the "too many command options" – Lovette Aug 21 '13 at 18:40
  • No sorry, not specifically for subdatasets, only for bands – Ryan Garnett Aug 21 '13 at 18:50
1

If you know how to use R, I suggest that you use gdalUtils package:

out.files <- list.files(getwd(), pattern="hdf$", full.names=FALSE) #create a 
list with names of the .hdf files (they should be stored in your workspace)

gdal_translate("Your_Image.hdf","Your_Image_Out.tif",sd_index=1) #extracts 
the NDVI band (sd_index=1) and converts to .tiff

gdalwarp("Your_Image_Out.tif","Your_Image_OutWGS84.tif",s_srs="+proj=sinu 
+lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs",
t_srs="+proj=longlat +datum=WGS84 +no_defs",srcnodata=-3000,dstnodata=-3000) 
#handles the conversion to WGS84

To automate the process you should do two for loops (one for the files and another for each band). The NDVI band are defined by sd_index parameter, if you want NDVI, EVI, quality, and reliability, the parameter should be (1,2,3 and 13).

My example converts .hdf to .tif and CRS=WGS84, I'm not sure if you can be converted to .img, just try it. If you need, I can help you with R or loops.

  • Note that your command your gdalwarp is only relevant for MODIS sinusoidal projection. MODIS products are supplied in one of three projects dependent on resolution, etc. – deepwinter Mar 20 '16 at 23:29

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.