Class: Geotagger::TrackImporter
- Inherits:
-
GpxUtils::TrackImporter
- Object
- GpxUtils::TrackImporter
- Geotagger::TrackImporter
- Defined in:
- lib/geotagger/track_importer.rb
Constant Summary collapse
- THRESHOLD =
5*60
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
-
.coord_valid?(lat, lon, elevation, time) ⇒ Boolean
Only import valid coords.
- .make_label(point, image = nil) ⇒ Object
Instance Method Summary collapse
- #add_image_marker(image) ⇒ Object
- #auto_marker ⇒ Object
- #determine_directions(index = 0) ⇒ Object
- #find_by_time(time) ⇒ Object
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
13 14 15 |
# File 'lib/geotagger/track_importer.rb', line 13 def verbose @verbose end |
Class Method Details
.coord_valid?(lat, lon, elevation, time) ⇒ Boolean
Only import valid coords
16 17 18 19 |
# 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) ⇒ Object
53 54 55 |
# 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 |
Instance Method Details
#add_image_marker(image) ⇒ Object
57 58 59 60 |
# File 'lib/geotagger/track_importer.rb', line 57 def add_image_marker(image) @images ||= [] @images << image end |
#auto_marker ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |