Thursday 12 November 2015

GPS: extracting Tracks from XML files with Gambas

You would have to be crazy to write your own XML editor when there are so many available, right?

Well, when opening the XML file from my Garmin eTrex in a variety of editors, my low power Linux laptop grinds to a halt.

As I only need to extract individual Tracks from the eTrex file, I decided to write my own program.

In an earlier post I mentioned that the eTrex enters data into a file every 10 seconds, including longitude, latitude and elevation. Each time the device is powered up, a new Track is created and added to this file. So what I need is some way to extract individual Tracks so they can be plotted on Google Earth or GPS Visualizer.

XML Editors

So why the problem with using a regular XML editor such as jEdit?

The Garmin XML file consists of one long line of text. When loaded into an XML editor, the editor tries to workout the configuration of tags, attributes and data, and then present the text with appropriate indentation.

These operations appear to be very resource intensive, but I'm surprised how much my ASUS struggles with this. I suspect there may be a low level issue with something associated with Lubuntu 15.10.

My Gambas App

Whatever the reason for the editor problems, as I only need to split Tracks from a Garmin file, I wrote a quick Gambas app to perform this task.

Since this program just performs a limited number of tasks, it performs very quickly. In operation, the eTrex file (always called Current.gpx) is selected in the FileChooser which results in a list of Tracks contained within this file.

Once a Track is selected from the ListBox, the complete Track can be saved as a .GPX or just the data as a .CSV file (i.e. latitude, longitude, elevation, date & time).

GPX files can be opened in Google Earth once the file type has been selected from the Google Earth "open" dialog. CSV files can be opened in a spreadsheet application such as LO Calc or MS Excel.

The Code

The software is fairly basic. Once the eTrex file is selected in the FileChooser I run a function to find Tracks.

When the GPX button is clicked, the selected Track is copied from the file.

The only tricky bit was determining that I needed some of the header and metadata to make this copied track acceptable to Google Earth.

As I don't understand the protocol, I decided to copy the whole header and attach it to the saved Track file. In addition I add the opening tags for track and track name, and the closing gpx tag.

The code also includes functions to save data as CSV, and deal with reading and writing files.

No comments:

Post a Comment