Created
June 6, 2014 14:40
-
-
Save cbachich/e881fd833fbdcd8019a4 to your computer and use it in GitHub Desktop.
A script that converts geotifs into mbtiles
This file contains 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
#!/usr/bin/env ruby | |
require 'optparse' | |
def run_cmd(text,command) | |
start_time = Time.now | |
puts "-- Starting #{text} at #{start_time.strftime '%I:%M:%S %b %d, %Y'}" | |
result = system command | |
end_time = Time.now | |
duration = "%0.2d" % ((end_time - start_time)/60) | |
puts "-- Finished #{text} at #{end_time.strftime '%I:%M:%S %b %d, %Y'} (took #{duration} minutes)" | |
result | |
end | |
options = {} | |
options[:out] = "tiles" | |
OptionParser.new do |opts| | |
opts.banner = "Usage: create_mbtiles.rb [options] GEOTIFS" | |
opts.on("--out [DIR]", String, "Tile Output Folder") do |out| | |
options[:out] = out | |
end | |
end.parse! | |
if ARGV.count == 1 | |
begin_time = Time.now | |
puts "---- Creating mbtiles from geotiffs at #{begin_time.strftime '%I:%M:%S %b %d, %Y'}" | |
worked = system "mkdir tmp" | |
worked = system "ls -1 #{ARGV[0]} > tmp/files.txt" if worked | |
worked = run_cmd 'Build VRT', "gdalbuildvrt -input_file_list tmp/files.txt tmp/files.vrt" if worked | |
worked = run_cmd 'Gdal Warp to Mercator', "gdalwarp -t_srs EPSG:3857 -of VRT tmp/files.vrt tmp/mercator.vrt" if worked | |
run_cmd 'Convert to MBTiles', "gdal2tiles.py -w openlayers -s EPSG:3857 tmp/mercator.vrt -t 'Sanborn Map Company' #{options[:out]}" if worked | |
run_cmd 'Cleanup', "rm -fr tmp" if worked | |
finish_time = Time.now | |
total_time = "%0.2d" % ((finish_time - begin_time)/60) | |
puts "---- Finished creating mbtiles from geotiffs at #{finish_time.strftime '%I:%M:%S %b %d, %Y'} (took #{total_time} minutes}" | |
else | |
puts "Usage: create_mbtiles.rb [options] GEOTIFS" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment