-
-
Save jqtrde/22839e82aae5341c28f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.mapbox.com/blog/processing-landsat-8/ | |
task :landsat_2014 => :environment do | |
dirs = Dir["#{Rails.root.to_s}/db/initial/raster/*"].reject {|q| q =~ /tar\.gz/ } | |
dirs.each do |dir| | |
scene_id = dir.split("/")[-1] | |
[4,3,2].each do |band| | |
`gdalwarp -t_srs EPSG:3857 #{dir}/#{scene_id}_B#{band}.TIF #{dir}/#{scene_id}_B#{band}-projected.tif` | |
end | |
`convert -combine #{dir}/#{scene_id}_B{4,3,2}-projected.tif #{dir}/#{scene_id}_RGB-projected.tif && \ | |
convert -channel B -gamma 0.925 -channel R -gamma 1.03 -channel RGB -sigmoidal-contrast 50x16% #{dir}/#{scene_id}_RGB-projected.tif #{dir}/#{scene_id}_RGB-projected-corrected.tif && \ | |
convert -depth 8 #{dir}/#{scene_id}_RGB-projected-corrected.tif #{dir}/#{scene_id}_RGB-projected-corrected-8bit.tif && \ | |
listgeo -tfw #{dir}/#{scene_id}_B4-projected.tif && \ | |
mv #{dir}/#{scene_id}_B4-projected.tfw #{dir}/#{scene_id}_RGB-projected-corrected-8bit.tfw && \ | |
gdal_edit.py -a_srs EPSG:3857 #{dir}/#{scene_id}_RGB-projected-corrected-8bit.tif && \ | |
gdal_translate -a_nodata 0 #{dir}/#{scene_id}_RGB-projected-corrected-8bit.tif #{dir}/#{scene_id}_RGB-projected-corrected-8bit-nodata.tif` | |
end | |
end | |
task :landsat_2014_merge => :environment do | |
dirs = Dir["#{Rails.root.to_s}/db/initial/raster/*"].reject {|q| q =~ /\..*$/ } | |
scenes = dirs.map do |q| | |
scene_id = q.split("/")[-1] | |
corrected = "#{q}/#{scene_id}_RGB-projected-corrected-8bit-nodata.tif" | |
end | |
`cd #{Rails.root.to_s}/db/initial/raster/ && gdalwarp --config GDAL_CACHEMAX 3000 -wm 3000 #{scenes.join(" ")} #{Rails.root.to_s}/db/initial/raster/merged.tif` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment