class Geotagger::TrackImporter
Constants
- THRESHOLD
Attributes
verbose[RW]
Public Class Methods
coord_valid?(lat, lon, elevation, time)
click to toggle source
Only import valid coords
# File lib/geotagger/track_importer.rb, line 16 def self.coord_valid?(lat, lon, elevation, time) return true if lat and lon and time return false end
make_label(point, image=nil)
click to toggle source
# File lib/geotagger/track_importer.rb, line 53 def self.make_label(point, image=nil) "#{point[:time].strftime('%H:%M:%S')}: (#{point[:lat]}, #{point[:lon]})#{image.nil? ? '' : image[:path]}" end
Public Instance Methods
add_image_marker(image)
click to toggle source
# File lib/geotagger/track_importer.rb, line 57 def add_image_marker(image) @images ||= [] @images << image end
auto_marker() { |{lat: coord, lon: coord, label: label}| ... }
click to toggle source
# File lib/geotagger/track_importer.rb, line 62 def auto_marker puts "Track starts: #{self.class.make_label self.coords[0]}" puts "Track ends: #{self.class.make_label self.coords[-1]}" coordset = self.coords.map do |coord| image = @images.select {|i| i[:coord] == coord}[0] {coord: coord, image: image} end prev_point = nil coordset.each_with_index do |co,index| coord = co[:coord] image = co[:image] puts "Labeling coord:#{coord} with image: #{image}" if image point = Geokit::LatLng.new(coord[:lat], coord[:lon]) if prev_point.nil? || (distance = point.distance_from(prev_point, units: :kms) > 0.02) label = self.class.make_label coord, image prev_point = point yield({lat: coord[:lat], lon: coord[:lon], label: label}) end end end
determine_directions(index=0)
click to toggle source
# File lib/geotagger/track_importer.rb, line 21 def determine_directions(index=0) if @coords.length > 1 previous_point = nil @coords.each do |coord| point = Geokit::LatLng.new(coord[:lat], coord[:lon]) if previous_point coord[:direction] = previous_point.heading_to(point) end previous_point = point end @coords[0][:direction] = @coords[1][:direction] end end
find_by_time(time)
click to toggle source
# File lib/geotagger/track_importer.rb, line 35 def find_by_time(time) selected_coords = @coords.select do |c| (c[:time].localtime - time.localtime).abs < THRESHOLD end selected_coords = selected_coords.sort do |a, b| (a[:time].localtime - time.localtime).abs <=> (b[:time].localtime - time.localtime).abs end if @verbose puts " - found #{selected_coords.size} coords within #{THRESHOLD}s from image time" if selected_coords.size > 0 puts " - best is #{selected_coords.first[:time].localtime}, time offset #{selected_coords.first[:time].localtime - time.localtime}" puts " - lat #{selected_coords.first[:lat]} lon #{selected_coords.first[:lon]}" end end return selected_coords.first end