Skip to content

Instantly share code, notes, and snippets.

@zydeco
Created October 8, 2014 21:02
Show Gist options
  • Save zydeco/6d8b19b31d7385b294e7 to your computer and use it in GitHub Desktop.
Save zydeco/6d8b19b31d7385b294e7 to your computer and use it in GitHub Desktop.
test geoutm data with coordinate-converter
require 'coordinate-converter'
require 'yaml'
testdata = File.open('testdata.yaml') {|f| YAML::load f }
ellipsoid_name = {
'Bessel 1841 Nambia ' => 'Bessel 1841 (Nambia)',
'Everest 1830 India' => 'Everest',
'Fischer 1960 Mercury ' => 'Fischer 1960 (Mercury)',
}
ellipsoid_name.default_proc = ->(h,k) { k }
failures = 0
testdata.each do |sample|
ellipsoid = ellipsoid_name[sample[:ellipsoid]]
zone_num = sample[:zone].to_i
hemisphere = sample[:zone][-1].match(/[N-X]/) ? 'N' : 'S'
coords = Coordinates.utm_to_lat_long(ellipsoid, sample[:northing].to_f, sample[:easting].to_f, "#{zone_num}#{hemisphere}")
if (sample[:latitude].to_f-coords[:lat]).abs > 0.00001 || (sample[:longitude].to_f-coords[:long]).abs > 0.00001
puts "FAIL: #{sample} != #{coords}"
failures += 1
end
end
puts "finished with #{failures} failures"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment