Top Level Namespace
Instance Method Summary collapse
- #extract_image_info(path) ⇒ Object
- #format_attachment_gps(file) ⇒ Object
- #to_decimal(dms) ⇒ Object
- #to_geojson(exif) ⇒ Object
Instance Method Details
#extract_image_info(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/exif2geojson.rb', line 40 def extract_image_info(path) image_types = "*.jpg" info = [] Dir.glob("#{File.(path)}/#{image_types}", File::FNM_CASEFOLD) do |jpg| begin info << (jpg) print "." rescue Exception => e print "E" end end puts "\n" { :type => "FeatureCollection", :features => info }.to_json end |
#format_attachment_gps(file) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/exif2geojson.rb', line 22 def (file) geometry, altitude = nil, nil body = File.read file r, w = IO.pipe w.write_nonblock(body) exif = EXIFR::JPEG.new(r) geometry = to_geojson(exif) altitude = exif.gps_altitude.to_f altitude = -altitude if exif.gps_altitude_ref.to_i < 0 { :type => "Feature", :geometry => geometry, :properties => { :altitude => altitude, :datetime => exif.date_time } } end |
#to_decimal(dms) ⇒ Object
4 5 6 |
# File 'lib/exif2geojson.rb', line 4 def to_decimal(dms) dms[0].to_f + dms[1].to_f / 60 + dms[2].to_f / 3600 end |
#to_geojson(exif) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/exif2geojson.rb', line 8 def to_geojson(exif) lat_exif = exif.gps_latitude lon_exif = exif.gps_longitude return "" unless lon_exif && lat_exif lon = to_decimal(lon_exif.map(&:to_f)) lon = -lon if exif.gps_longitude_ref == "W" lat = to_decimal(lat_exif.map(&:to_f)) lat = -lat if exif.gps_latitude_ref == "S" { :type => "Point", :coordinates => [lon, lat] } end |