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?
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:
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.
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.