7     attr_reader :possible_points, :actual_points, :tracksegs
 
  13     def parse_file(reader)
 
  18         when XML::Reader::TYPE_ELEMENT
 
  19           if reader.name == "trkpt"
 
  20             point = TrkPt.new(@tracksegs, reader["lat"].to_f, reader["lon"].to_f)
 
  22           elsif reader.name == "ele" && point
 
  23             point.altitude = reader.read_string.to_f
 
  24           elsif reader.name == "time" && point
 
  25             point.timestamp = Time.parse(reader.read_string)
 
  27         when XML::Reader::TYPE_END_ELEMENT
 
  28           if reader.name == "trkpt" && point && point.valid?
 
  32           elsif reader.name == "trkseg"
 
  40       return enum_for(:points) unless block_given?
 
  47         Archive::Reader.open_filename(@file).each_entry_with_data do |_entry, data|
 
  48           parse_file(XML::Reader.string(data), &block)
 
  51         io = ::File.open(@file)
 
  53         case MimeMagic.by_magic(io)&.type
 
  54         when "application/gzip" then io = Zlib::GzipReader.open(@file)
 
  55         when "application/x-bzip" then io = Bzip2::FFI::Reader.open(@file)
 
  58         parse_file(XML::Reader.io(io), &block)
 
  62     def picture(min_lat, min_lon, max_lat, max_lon, num_points)
 
  68       points_per_frame = (num_points.to_f / nframes).ceil
 
  70       proj = OSM::Mercator.new(min_lat, min_lon, max_lat, max_lon, width, height)
 
  74       (0...nframes).each do |n|
 
  75         frames[n] = GD2::Image::IndexedColor.new(width, height)
 
  76         black = frames[n].palette.allocate(GD2::Color[0, 0, 0])
 
  77         white = frames[n].palette.allocate(GD2::Color[255, 255, 255])
 
  78         grey = frames[n].palette.allocate(GD2::Color[187, 187, 187])
 
  80         frames[n].draw do |pen|
 
  82           pen.rectangle(0, 0, width, height, true)
 
  85         frames[n].draw do |pen|
 
  87           pen.anti_aliasing = true
 
  88           pen.dont_blend = false
 
  95           points.each_with_index do |p, pt|
 
  96             px = proj.x(p.longitude)
 
  97             py = proj.y(p.latitude)
 
  99             if (pt >= (points_per_frame * n)) && (pt <= (points_per_frame * (n + 1)))
 
 107             pen.line(px, py, oldpx, oldpy) unless first
 
 115       image = GD2::AnimatedGif.new
 
 116       image.add(frames.first)
 
 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