7 attr_reader :possible_points
8 attr_reader :actual_points
15 def parse_file(reader)
19 if reader.node_type == XML::Reader::TYPE_ELEMENT
20 if reader.name == "trkpt"
21 point = TrkPt.new(@tracksegs, reader["lat"].to_f, reader["lon"].to_f)
23 elsif reader.name == "ele" && point
24 point.altitude = reader.read_string.to_f
25 elsif reader.name == "time" && point
26 point.timestamp = Time.parse(reader.read_string)
28 elsif reader.node_type == XML::Reader::TYPE_END_ELEMENT
29 if reader.name == "trkpt" && point && point.valid?
33 elsif reader.name == "trkseg"
41 return enum_for(:points) unless block_given?
48 Archive::Reader.open_filename(@file).each_entry_with_data do |_entry, data|
49 parse_file(XML::Reader.string(data), &block)
52 io = ::File.open(@file)
54 case MimeMagic.by_magic(io).type
55 when "application/gzip" then io = Zlib::GzipReader.open(@file)
56 when "application/x-bzip" then io = Bzip2::FFI::Reader.open(@file)
59 parse_file(XML::Reader.io(io), &block)
63 def picture(min_lat, min_lon, max_lat, max_lon, num_points)
69 points_per_frame = num_points / nframes
71 proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
75 (0...nframes).each do |n|
76 frames[n] = GD2::Image::IndexedColor.new(width, height)
77 black = frames[n].palette.allocate(GD2::Color[0, 0, 0])
78 white = frames[n].palette.allocate(GD2::Color[255, 255, 255])
79 grey = frames[n].palette.allocate(GD2::Color[187, 187, 187])
81 frames[n].draw do |pen|
83 pen.rectangle(0, 0, width, height, true)
86 frames[n].draw do |pen|
88 pen.anti_aliasing = true
89 pen.dont_blend = false
96 points.each_with_index do |p, pt|
97 px = proj.x(p.longitude)
98 py = proj.y(p.latitude)
100 if (pt >= (points_per_frame * n)) && (pt <= (points_per_frame * (n + 1)))
108 pen.line(px, py, oldpx, oldpy) unless first
116 image = GD2::AnimatedGif.new
117 frames.each do |frame|
118 image.add(frame, :delay => delay)
122 output = StringIO.new
127 def icon(min_lat, min_lon, max_lat, max_lon)
130 proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
132 image = GD2::Image::IndexedColor.new(width, height)
134 black = image.palette.allocate(GD2::Color[0, 0, 0])
135 white = image.palette.allocate(GD2::Color[255, 255, 255])
139 pen.rectangle(0, 0, width, height, true)
144 pen.anti_aliasing = true
145 pen.dont_blend = false
153 px = proj.x(p.longitude)
154 py = proj.y(p.latitude)
156 pen.line(px, py, oldpx, oldpy) unless first
168 TrkPt = Struct.new(:segment, :latitude, :longitude, :altitude, :timestamp) do
170 latitude && longitude && timestamp &&
171 latitude >= -90 && latitude <= 90 &&
172 longitude >= -180 && longitude <= 180