Created
August 23, 2008 14:12
-
-
Save r38y/6920 to your computer and use it in GitHub Desktop.
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
require 'rational' | |
require 'rubygems' | |
require 'exifr' rescue nil | |
module Randy | |
# converts dms in [Rational(75, 1), Rational(452, 25), Rational(0, 1)] to a float | |
def self.dms_to_float(dms) | |
if dms == nil || (dms.size != 3) && !dms.map{|i| i.class == Rational}.all? | |
raise ArgumentError, "We need an array of 3 Rational numbers. k thx bai." | |
end | |
dms[0].to_f + ((dms[1].to_f + (dms[2].to_f / 60)) / 60) | |
end | |
end | |
if ARGV.size != 0 && Object.const_defined?(:EXIFR) | |
ARGV.each do |img_name| | |
img = EXIFR::JPEG.new(img_name) | |
puts "-"*21 | |
puts "Lat: #{Randy.dms_to_float(img.gps_latitude)}" | |
puts "Lng: #{Randy.dms_to_float(img.gps_longitude)}" | |
end | |
else | |
puts "DMS: [Rational(75, 1), Rational(452, 25), Rational(0, 1)]" | |
puts "Float: #{Randy.dms_to_float([Rational(75, 1), Rational(452, 25), Rational(0, 1)])}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment