Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This is my first post, I hope I don't screw it up. We have about 400 MODIS HDF4 files we are looking to batch process in the ArcGIS 10 or Python environment. The tools we are looking to use are Extract Subdataset (HDF4 files have subdatasets and we are only interested in one of them, which its index number is 1), ProjectRaster(to UTM 11 NAD 83), convert HDF4 files to TIFF (although I believe this can be done when executing the Extract Subdataset tool as it lets you choose an output file format), Int (we need the raster file to have an attribute table with pixel values). I've tried performing these tasks in modelbuilder in batch mode but i've had no success in properly setting it up.

We are interested in both the ModelBuilder and Python approach.

It would be great if someone can post some batch processing code that would apply to these tools.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Sounds do-able. I would suggest looking at the docs, specifically the sections on listing data and the tools you need to use, such as the Extract Subdataset tool - there are lots of samples in both of those sections to get you going. If I understand the issue properly, you need to get a list of the rasters, then iterate through that list, processing as you go: Extract Subdataset (save as tiff) -> Project -> Convert to int (you could use Map Algebra to do that).

EDIT: To change the filename, use some slicing to get only the name without the extension:

arcpy.ExtractSubDataset_management(hdf,"U:\\temp\\hdf\\subdataset_files\\" + hdf[:4] + ".tif", "0")
share|improve this answer
    
Yes, you understood me correctly, chad. I attempted to batch process using listing but I wasn't sure if that method was capable of performing the functions. It appears that it is. I'll take another look. Thanks for the recomendations. –  dchaboya Dec 6 '11 at 16:35
    
I have another question. I've succeded in performing Extract Subdataset as a batch. Now I would like to know how to change the name of output files. When I do this arcpy.ExtractSubDataset_management(hdf,"U:\\temp\\hdf\\subdataset_files\\" + hdf + ".tif", "0")it adds the .tif (i'm exporting here) and I would like it to remove the .hdf part of the name of the original file. –  dchaboya Dec 6 '11 at 20:25
    
@user1081626 - see my edits for changing output file name –  Chad Cooper Dec 7 '11 at 1:52

I routinely do this with GDAL and a simple bash script. You can also do ith with python, but I think this is quite straightforward and easier to understand

#!/bin/bash

# This script reprojects and subsets a bunch of HDF files stored in
# a given dir (WORKDIR). The output is a GeoTIFF formatted file.
#

WORKDIR="./" # Where all HDF files are stored
TARGET_SRS="EPSG:2153" # Your projection. See spatialreference.org
TARGET_EXTENT="0 0 10 10" # The target's extent (xmin ymin xmax ymax)
                          # In target units!
TARGET_RES="1000" # Whatever you want the output resolution to be
for granule in ${WORKDIR}/*.hdf
do
    output_name=`basename $granule .hdf`.tif
    gdalwarp -t_srs ${TARGET_SRS} -te ${TARGET_EXTENT} -tr ${TARGET_RES}\
             -of GTiff -co "COMPRESS=LZW" \
             'HDF4_EOS:EOS_GRID:"'${granule}'":MOD_Grid_MOD15A2:Fpar_1km' \
             ${output_name}
done

This is an example for the fAPAR layer in the MOD15 product, so you'd have to modify that particular line for whatever it is that you want.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.