Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
desc "build cropped heightmap"
task :build_srtm do |t|
# have to download the SRTM_W_250m.tif first from cgiar
system "gdalwarp ./db/initial/srtm/SRTM_W_250m.tif ./db/initial/srtm/cropped.tif -t_srs 'EPSG:102003' -cutline ./db/initial/shapes/shoreline/us.shp -crop_to_cutline"
end
desc "build cropped raster from heightmap"
task :build_raster do |t|
STDOUT.sync = true
(200401..200407).each do |t|
puts "#{t}"
system "gdal_translate ./db/initial/bluemarble/world.#{t}.3x21600x10800.jpg ./db/initial/bluemarble/marble-earth-#{t}-ref.tif -a_srs 'EPSG:102003' -a_ullr -180 90 180 -90"
system "gdalwarp ./db/initial/bluemarble/marble-earth-#{t}-ref.tif ./db/initial/bluemarble/#{t}-background-cropped.tif -t_srs 'EPSG:4326' -cutline ./db/initial/shapes/shoreline/us.shp -crop_to_cutline -dstalpha -multi -overwrite"
end
end
desc "get blue marble"
task :get_bm do |t|
`mkdir -p ./db/initial/bluemarble/`
STDOUT.sync = true
(200401..200407).each do |t|
system "cd ./db/initial/bluemarble/ && wget --continue http://earthobservatory.nasa.gov/Features/BlueMarble/images_bmng/2km/world.#{t}.3x21600x10800.jpg"
end
end
desc "make rasters into pngs"
task :srtm_to_png do |t|
width = 2258243.997 - -2356113.743
height = 1565781.660 - -1337505.346
twidth = 1000
STDOUT.sync = true
system "gdal_translate ./db/initial/srtm/cropped.tif ./db/initial/srtm/height_2px.png -outsize #{twidth} #{twidth * height / width} -of PNG -ot UInt16"
system "./lib/packmap/packmap ./db/initial/srtm/height_2px.png ./db/initial/srtm/height.tiff"
system "gdal_translate ./db/initial/srtm/height.tiff ./app/assets/images/height.png -of PNG"
(200401..200407).each do |t|
system "gdal_translate ./db/initial/bluemarble/#{t}-background-cropped.tif ./app/assets/images/marble-earth-#{t}.png -outsize #{twidth} #{twidth * height / width} -of PNG"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment