Created
          November 24, 2012 23:16 
        
      - 
      
 - 
        
Save hannahwhy/4141766 to your computer and use it in GitHub Desktop.  
    PNG -> GeoTIFF conversion for Blue Marble PNGs
  
        
  
    
      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
    
  
  
    
  | 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 | 
  
    
      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
    
  
  
    
  | 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
  
            
More info and source data:
http://visibleearth.nasa.gov/view.php?id=73776
http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73776/readme.pdf (extent data)