Category Archives: Running

Fixing Marble KML files

So today I’ve woke up and went for my morning run. I’ve decided to use Marble for tracking on my N900 this time, as eCoach has failed me the couple of times and was not able to produce proper tracks. Everything went smoothly and I’ve got a nice track, which I saved after I’ve finished. Marble supports only KML files, so when I got home, I knew I must convert it to GPX prior to uploading it to (one of the best sites I’ve seen for analyzing your tracking data).

The conversion

Using guidelines from the Marble/Tracking page I’ve used the following command:

$ gpsbabel -i kml -f running-2011-10-11_071712.kml -o gpx -f running-2011-10-11_071712.gpx

Please bare in mind that I’m running this on a Fedora 14 install which misses the gpsbabel GUI. I was able to find packages for F15/F16 so if you are using one of those you should have it in the Fedora Repositories.

Having the file converted I’ve tried to upload it to, but this is where the things got ugly. The following error was thrown at me:

Warning: Division by zero in /var/www/vhosts/ on line 103
Warning: Division by zero in /var/www/vhosts/ on line 103
Warning: Division by zero in /var/www/vhosts/ on line 103

The Problem

After short investigation I’ve found that my other (eCoach) gpx tracks were having the attribute for each trackpoint () and the converted file was missing them. The google search resulted in nothing of a help that would allow me to inject the timestamps inside this trackpoints, so the logical continuation was to do it myself 🙂

The Fix

For the purpose of this task, a simple perl script was created. You’ll need Date::Parse perl module (perl-TimeDate package on Fedora 14):

#!/usr/bin/perl -w

use Date::Parse;
use POSIX qw/strftime/;

# read the input file
$num_args = $#ARGV + 1;
if ($num_args != 1) {
  print "\nUsage: $0 <input_file.gpx>\n";

# if you are consolidating points in gpsbabel, change this accordingly
# by default marble writes points every 1 second
my $timeStep = 1;

my $inFile = $ARGV[0];
open FILE, "< $inFile" or die "Can't open $inFile : $!";

# calculate the timezone
my $tz = strftime("%z", localtime(time()));
$tz =~ s/(\d{2})(\d{2})/$1:$2/;
my $unixTime = 0;

  print $_;
    # get the starting time
    $unixTime = str2time($1);
    # print ISO8601 formated time
    print "  <time>" . strftime("%Y-%m-%dT%H:%M:%S", localtime($unixTime)) . $tz . "</time>\n";
    $unixTime += $timeStep;
close FILE

The only argument that this script takes is the input gpx file, generated with gpsbabel and the output is thrown on stdout. What that script does is it takes the initial time when the gpx file was generated and injects <time></time> values from it, increasing it after every trackpoint with one second. Of course this is not perfect as the timestamps are shifted in time and are not the real values, but at least that allows me to insert the file and analyze it on MapMyTracks. Maybe I’ll post update on that script that will take also as input the KML file, where the time when the files was saved is used, and reverse it back to the first trackpoint. That should give more accurate gpx files.

It seems that I’ll be using this half-baked solution for uploading my tracks, as it works and generates pretty detailed track (one trackpoint per second), unlike eCoach that does this at best every 2 seconds (and does not work on my device :-). Here is the final result on MapMyTracks.


EDIT: I’ve found what’s wrong with eCoach and how to fix it

Tagged , , , , , , ,