[GIS] Extracting multiple Subdataset from hdf files to geotiff format using ArcPy

arcgis-10.1arcpygeotiff-tiffhdfspatial-analyst

I have 165 hdf files(monthly data) of EVI(Enhanced Vegetation Index) , I need to convert them to a geotiff format. In ArcMap 10.1 I can only extract the data one file at a time.

I have this python code for extracting the data. The problem is it only extracts 11 tiles of one month that covers the study area. Say for example January only.
How do I change it so that it accounts for all 165 files at one go.

import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension("Spatial")

inPath='D:/Input/'
outPath='D:/OutPut/'
env.workspace = inPath
arcpy.env.scratchWorkspace = inPath
hdfList = arcpy.ListRasters('*','HDF')

for hdf in hdfList:
    eviName=hdf[8:16] + ".tif"
    print "Subsetting EVI band from ....."+str(hdf)
    data1=arcpy.ExtractSubDataset_management(hdf,outPath + hdf[8:16] + ".tif", "1")
print "Done"

Best Answer

you can right click on the extract subdataset tool and select "batch". Then you can open all files (right click on input, browse option) and launch the extraction for them (clicking "validate" will automatically create valid output names).

enter image description here

As for your Python script, it looks OK but I would use a more robust code for the output file name (os.path.join as mentioned by @Michael Miles Stimson and split to avoid counting the character with the risk of something like "..tif"

os.path.join(outPath, hdf.split(".")[1] + ".tif"))
Related Question