Skip to content

Instantly share code, notes, and snippets.

@oeon
Last active August 29, 2015 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oeon/33f609c3502918d4a7c3 to your computer and use it in GitHub Desktop.
Save oeon/33f609c3502918d4a7c3 to your computer and use it in GitHub Desktop.
Processing Landsat 8 imagery in Windows with OSGeo4W Shell and ImageMagick
::modified from Mapbox's guide https://www.mapbox.com/guides/processing-satellite-imagery/ for Windows
::requires OSGeo4W Shell (comes installed with QGIS) and ImageMagick http://www.imagemagick.org/script/binary-releases.php#windows
::I paste all of the lines below into the OSGeo4W Shell which I've changed directory to my expanded Landsat archive e.g. `C:\Users\joe\Downloads\LC80430352015089LGN00.tar>`
::establish an id variable
SET id=LC81600432014154LGN00
::use a for loop to reproject each of the bands you will be working with.
FOR %B in (4,3,2) DO gdalwarp -t_srs EPSG:3857 %id%"_B"%B.tif %B-projected.tif
::translate each of your bands into the 8-bit format with default settings of -ot and -scale
::i don't think Windows can do brace expansion in scripts
gdal_translate -ot Byte -scale 0 65535 0 255 4-projected.tif 4-projected-scaled.tif
gdal_translate -ot Byte -scale 0 65535 0 255 3-projected.tif 3-projected-scaled.tif
gdal_translate -ot Byte -scale 0 65535 0 255 2-projected.tif 2-projected-scaled.tif
::merge the three reprojected band images into a single composite image
::OSGeo4W Shell did not like the `-v` flag
python C:\OSGeo4W64\bin\gdal_merge.py -ot Byte -separate -of GTiff -co PHOTOMETRIC=RGB -o %id%-RGB-scaled.tif 4-projected-scaled.tif 3-projected-scaled.tif 2-projected-scaled.tif
::color corrections in blue bands to deal with haze factor,
::and across all bands for brightness, contrast and saturation
"C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe" -channel B -gamma 1.05 -channel RGB -sigmoidal-contrast 20,20% -modulate 100,150 %id%-RGB-scaled.tif %id%-RGB-scaled-cc.tif
::use a cubic downsampling method to add overview
::(other interpolation methods are available)
gdaladdo -r cubic %id%-RGB-scaled-cc.tif 2 4 8 10 12
::call the TIFF worldfile for the requested image,
::change name of file to match file needing georeference,
::and apply georeference
listgeo -tfw 3-projected.tif
mv 3-projected.tfw %id%-RGB-scaled-cc.tfw
gdal_edit.py -a_srs EPSG:3857 %id%-RGB-scaled-cc.tif
::remove black background
gdalwarp -srcnodata 0 -dstalpha %id%-RGB-scaled-cc.tif %id%-RGB-scaled-cc-2.tif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment