Skip to content

Instantly share code, notes, and snippets.

@khufkens
Created April 14, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khufkens/4efd2c6ebe38bb4dd2e7f58b4d66600e to your computer and use it in GitHub Desktop.
Save khufkens/4efd2c6ebe38bb4dd2e7f58b4d66600e to your computer and use it in GitHub Desktop.
Converts MOD04 'swath' data to gridded data, using internal ground control point data.
#!/bin/bash
#
# swath to grid conversion for
# MOD04 reflectance data
#
# get the reprojection information
gdal_translate -of VRT HDF4_EOS:EOS_SWATH:"$1":mod04:Mean_Reflectance_Land land.vrt
gdal_translate -of VRT HDF4_EOS:EOS_SWATH:"$1":mod04:Mean_Reflectance_Ocean ocean.vrt
# delete the bad ground control points
sed '/X=\"-9.990000000000E+02\"/d' land.vrt
sed '/X=\"-9.990000000000E+02\"/d' ocean.vrt
filename=$(basename "$1")
filename="${filename%.*}"
# reproject the data using the cleaned up VRT file
gdalwarp -overwrite -of GTIFF -tps land.vrt $filename.land.reflectance.tif
gdalwarp -overwrite -of GTIFF -tps ocean.vrt $filename.ocean.reflectance.tif
#gdalbuildvrt -separate stack.vrt lsat1.tif lsat2.tif ...
#gdal_translate stack.vrt stack.tif
#gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment