GPX problem from Spot device

Discuss any problems and questions you may have about using EveryTrail

Moderator: chris

GPX problem from Spot device

Postby salgo60 on Wed Aug 04, 2010 9:51 pm

If I upload a file exported from Findmespot (I use a spot device to track my trips) where the GPS file has

Code: Select all
<trkpt lat="67.31075" lon="16.69508">
<name>3-TRACK</name>
<time>Tue Aug 03 07:56:36 UTC 2010</time>
<cmt>0-7388638 @ Tue Aug 03 07:56:36 UTC 2010</cmt>
<desc>0-7388638 @ Tue Aug 03 07:56:36 UTC 2010</desc>
</trkpt>


I get the following when exporting from everytrail after first importing the above ==> my feeling is that Everytrail has problem to read the time format correct

Code: Select all
<trkpt lat="67.310750000" lon="16.695080000">
  <ele>0.000000</ele>
  <time>-1-12-03T00:00:00Z</time>
</trkpt>


This also makes the "rerun of the trip" wrong

http://www.everytrail.com/view_trip.php?trip_id=737300

Question what is the correct time format?!?!
Last edited by salgo60 on Thu Aug 05, 2010 10:40 pm, edited 1 time in total.
http://images.everytrail.com/userpics/83615-magnusstor.jpgUser avatar
salgo60
 
Posts: 35
Joined: Wed Sep 23, 2009 6:01 am

Re: GPX problem from Spot device

Postby salgo60 on Thu Aug 05, 2010 3:43 am

If I check http://www.topografix.com/gpx_manual.asp

it says
Code: Select all
<time>2002-02-10T21:01:29.250Z</time>


Creation/modification timestamp for element. Date and time in are in Univeral Coordinated Time (UTC), not local time! Conforms to ISO 8601 specification for date/time representation. Fractional seconds are allowed for millisecond timing in tracklogs.
<KEYWORDS>


That means that http://international.findmespot.com/ exports in the wrong date format
http://images.everytrail.com/userpics/83615-magnusstor.jpgUser avatar
salgo60
 
Posts: 35
Joined: Wed Sep 23, 2009 6:01 am

Re: GPX problem from Spot device

Postby chris on Thu Aug 05, 2010 10:14 am

Thanks for reporting, we'll look into it further and contact the appropriate person.
See all of my travels and fun experiences on my travel blog: http://www.gone-wandering.com
http://images.everytrail.com/userpics/33-chris.jpgUser avatar
chris
 
Posts: 2357
Joined: Sun Jan 13, 2008 6:58 pm
Location: San Francisco, CA

Re: GPX problem from Spot device

Postby salgo60 on Sat Aug 07, 2010 6:29 am

I did some coding and fixed the problem of the exported GPX file from SPOT

Problem was
  1. Wrong Date format should be in form ISO 8601
  2. The trkpt element on a trkseg was sorted in wrong date order ==> replay of a trip in everytrail was wrong per trkseg
    compare 741973 and 742193



Code in c# to fix it

Code: Select all
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;

namespace SPOTXmlError
{
    class Program
    {
        internal static XNamespace ns = "http://www.topografix.com/GPX/1/1";
        static void Main(string[] args)
        {
            XDocument doc = ReadSpotDoc();
            XDocument newDoc = ConvertTimeElement(doc);
            XDocument sortDoc = SortTrackPoints(doc);
            sortDoc.Save("Spotout.gpx");
        }

        private static XDocument SortTrackPoints(XDocument doc)
        {
            if (doc.Root != null)
            {
                var trksegs = doc.Root.Descendants(ns + "trkseg");
                foreach (var trkseg in trksegs)
                {
                    List<XElement> trkptList = trkseg.Elements(ns + "trkpt").OrderBy(x => (string)x.Element(ns + "time")).ToList();
                    trkseg.RemoveAll();
                    trkseg.Add(trkptList);
                }
            }
            return doc;

        }

        private static XDocument ConvertTimeElement(XDocument doc)
        {
            if (doc.Root != null)
            {
                var times = doc.Root.Descendants(ns + "time").ToList();
                foreach (var time in times)
                    time.SetValue((string)ConvertSpotDateFormat(time));
            }
            return doc;
        }

        private static string ConvertSpotDateFormat(XNode time)
        {
            DateTime dt;
            DateTimeStyles styles = DateTimeStyles.AssumeUniversal;
            const string pattern = "ddd MMM dd HH:mm:ss UTC yyyy";
            CultureInfo enUs = new CultureInfo("en-US");
            bool isOk = DateTime.TryParseExact(time.ToString(), pattern, enUs, styles, out dt);
            if (isOk)
                return dt.ToString("o");

            return "Date Conversion Error";
        }

        private static XDocument ReadSpotDoc()
        {
            XDocument doc = XDocument.Load("Spot.gpx");
            return doc;
        }

}
http://images.everytrail.com/userpics/83615-magnusstor.jpgUser avatar
salgo60
 
Posts: 35
Joined: Wed Sep 23, 2009 6:01 am


Return to Problems