- # This piece of magic reads a GPX with SAX and spits out
- # lat/lng and stuff
- #
- # This would print every latitude value:
- #
- # gpx = OSM::GPXImporter.new('somefile.gpx')
- # gpx.points {|p| puts p['latitude']}
- class GPXImporter
- # FIXME swap REXML for libXML
- attr_reader :possible_points
- attr_reader :actual_points
- attr_reader :tracksegs
-
- def initialize(file)
- @file = file
- end
-
- def points
- @possible_points = 0
- @actual_points = 0
- @tracksegs = 0
-
- lat = -1
- lon = -1
- ele = -1
- date = DateTime.now();
- gotlatlon = false
- gotele = false
- gotdate = false
-
- @file.rewind
-
- parser = REXML::Parsers::SAX2Parser.new(@file)
-
- parser.listen( :start_element, %w{ trkpt }) do |uri,localname,qname,attributes|
- lat = attributes['lat'].to_f
- lon = attributes['lon'].to_f
- gotlatlon = true
- gotele = false
- gotdate = false
- @possible_points += 1
- end