points_to_gcp.rb 570 B

123456789101112131415161718
  1. #!/usr/bin/env ruby
  2. require 'rubygems'
  3. require 'fastercsv'
  4. src_head = [:mapX,:mapY,:pixelX,:pixelY,:enable,:comment]
  5. dst=$stdout
  6. FCSV.new($stdin).each do |row|
  7. next if row[0].to_i == 0
  8. hash = {}
  9. src_head.each_index {|i| hash[ src_head[i] ] = row[i]}
  10. [:mapX,:mapY,:pixelX,:pixelY].each {|k| hash[k] = hash[k].to_f}
  11. [:pixelX,:pixelY].each {|k| hash[k] = hash[k].to_i}
  12. hash[ :pixelY ] = -hash[ :pixelY ] if hash[ :pixelY ] < 0 # flip to positive
  13. # pixel line easting northing
  14. dst.write "-gcp #{hash[:pixelX]} #{hash[:pixelY]} #{hash[:mapX]} #{hash[:mapY]} "
  15. end