Ruby GPX File Analyzer

Advise what can analyze a GPX file in Ruby?

I tried gpx , but it does not work with Ruby Enterprise Edition ( https://github.com/dougfales/gpx/issues/1 ).

I would not want to write a parser.

+3
source share
1 answer

I was looking for the same thing, but ultimately the GPX file is another XML file, so you can parse it with XML syntax libraries like Nokogiri . This is how I extract all latitudes and longitudes from the GPX log:

#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::XML(open(my-log.gpx))
trackpoints = doc.xpath('//xmlns:trkpt/')
points = Array.new
trackpoints.each do |trkpt|
  points << [trkpt.xpath('@lat').to_s.to_f, trkpt.xpath('@lon').to_s.to_f]
end

There are probably better ways to do this, but it works for me.

+10
source

Source: https://habr.com/ru/post/1748795/


All Articles