Skip to content

Instantly share code, notes, and snippets.

@adamfast
Forked from hannahwhy/convert.rb
Created June 30, 2013 23:07
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 adamfast/5897373 to your computer and use it in GitHub Desktop.
Save adamfast/5897373 to your computer and use it in GitHub Desktop.
def trans_lat(lat)
lat =~ /([0-9]+)([NS])/
num, dir = $1.to_i, $2
dir == 'S' ? -num : num
end
def trans_long(long)
long =~ /([0-9]+)([EW])/
num, dir = $1.to_i, $2
dir == 'W' ? -num : num
end
data = if ARGV.length > 0
ARGV.map { |f| File.read(f) }.join("\n")
else
$stdin.read
end
data.split("\n").each do |row|
fn, ul_lat, ul_long, lr_lat, lr_long, res = row.split("\t")
dst = fn.sub(File.extname(fn), '.tiff')
uly = trans_lat(ul_lat)
ulx = trans_long(ul_long)
lry = trans_lat(lr_lat)
lrx = trans_long(lr_long)
cmd = "gdal_translate -a_srs WGS84 -a_ullr #{ulx} #{uly} #{lrx} #{lry} #{fn} /gtiff/output/#{dst}"
puts cmd
`#{cmd}`
end
world.topo.200408.3x21600x21600.A1.png 90N 180W 0N 90W 240
world.topo.200408.3x21600x21600.A2.png 0N 180W 90S 90W 240
world.topo.200408.3x21600x21600.B1.png 90N 90W 0N 0W 240
world.topo.200408.3x21600x21600.B2.png 0N 90W 90S 0W 240
world.topo.200408.3x21600x21600.C1.png 90N 0W 0N 90E 240
world.topo.200408.3x21600x21600.C2.png 0N 0W 90S 90E 240
world.topo.200408.3x21600x21600.D1.png 90N 90E 0N 180E 240
world.topo.200408.3x21600x21600.D2.png 0N 90E 90S 180E 240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment