全球土地被覆データMCD12Q1の作成 HDFダウンロード〜GeoTiffの抽出・マージ(モザイク)〜投影法の変換まで

シェルとGDALのみでいきます。
1.HDFダウンロード
wget -r -l 1 -A hdf http://e4ftl01.cr.usgs.gov/MOTA/MCD12Q1.051/2009.01.01/

2. 各HDFファイルからTIFFに変換。今回はLand Cover Type 1 (2001): IGBP global vegetation classification schemeのみをピックアップします。

以下のシェル(mcd12q1_hdf_to_tif.sh)を実行する(元ネタはどこだったっけ・・・)
#!/bin/bash
#Set field separator to linefeeds rather than spaces
echo "#!/bin/bash" > batch.sh
chmod +x batch.sh

for FILE in *hdf
do
echo $FILE
LAYERS=$(gdalinfo $FILE | grep SUBDATASET | grep NAME | grep Land_Cover_Type_1 | sed 's/[A-Z0-9\_]*=//g')

for LAYER in $LAYERS
do
LAYER=$(echo $LAYER | sed 's/ //g')
NEWFILE=$(echo $LAYER | \
sed 's/HDF4_EOS:EOS_GRID:"//g' | sed 's/.hdf":Grid:/_/g' | sed 's/ //g' | sed 's/"//g' | sed 's/ //g'| sed 's/:/./g').tif
CMD="gdal_translate -of GTiff '${LAYER}' $NEWFILE"
echo $CMD >> batch.sh
done
done

exec ./batch.sh

3.できたGeoTiffファイルをマージする

http://invisibleroads.com/tutorials/gdal-raster-merge.html

このシェル(gdal_tif_merge.tif)を実行
#!/bin/bash
#Set field separator to linefeeds rather than spaces
echo "#!/bin/bash" > batch.sh
chmod +x batch.sh
#IFS=$'\n'

LIST=`ls | grep Land_Cover_Type_1.tif`
LIST2=`echo $LIST | sed 's/\n/ /g'`
gdal_merge.py $LIST2 -o MOD12Q1_global.tif



4,投影法の変換もGDALで。
WGS84(EPSG:4326)へ変換する。

gdalwarp -t_srs EPSG:4326 -of GTiff MOD12Q1_global.tif MOD12Q1_global_wgs84.tif