Tuesday, 18 December 2012

Fixing your GPS track

Annoyingly I forgot restarting my watch after a went to the toilet. Luckily there is a fix to such.

The annoyance
Today when I was out running I, as many times before, stopped my watch during a short break and forgot restarting it. A few kilometres later I realised that my GPS map would get one of those irritating straight lines on Garmin Connect. Getting back home I did some research on how to manually correct my recorded exercise, however I didn't find that much on the topic. Hence this post on what I ended up doing.

Locating the original
When a Garmin device communicates with a computer a couple of files are transferred. Here is a page on how to find them. My own file I found in the directory:
C:\Users\klevstul\AppData\Roaming\Garmin\Devices\3841664372\History
The activity file was named:
2012-12-18-042614.TCX

Copy it
Next thing is to make a copy of this .tcx file, to your desktop or another location you might prefer.

Locating the gap
Open your copy of the .tcx file in an editor (personally I use Komodo Edit, but most text editors should do). What you have to do now is to find the spot for the missing data. Every time you press the start / stop button on your device a new <Track> entry is created in the training file. For each time the Garmin device is recording data a new <Trackpoint> entry is created. Each <Track> consists of one or (most likely) many <Trackpoint> entries.

Looking at your original training session in Garmin Connect can help you out on finding where to insert new data (where the gap / straight line is). Open your activity in the "Player" and go the last point before the straight line starts. In my case (as you can see on the screenshot below) the line starts after about 7.32 km.

7.32 is the number to remember.

Now, open the copy of the .cfx in your editor of choice and scroll down until you reach the point where the straight line starts. You should see that the following XML code / tags are located where the gap is:

</Track>
<Track>

More concretely, in my case it looked like this:
... cont ...
          <Trackpoint>
            <Time>2012-12-18T04:23:11Z</Time>
            <Position>
              <LatitudeDegrees>35.7740202</LatitudeDegrees>
              <LongitudeDegrees>139.4144446</LongitudeDegrees>
            </Position>
            <AltitudeMeters>164.8000031</AltitudeMeters>
            <DistanceMeters>7319.4799805</DistanceMeters>
            <Extensions>
              <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2" CadenceSensor="Footpod">
                <Speed>2.4879999</Speed>
              </TPX>
            </Extensions>
          </Trackpoint>
        </Track>
        <Track>
          <Trackpoint>
            <Time>2012-12-18T04:52:44Z</Time>
            <Position>
              <LatitudeDegrees>35.7836677</LatitudeDegrees>
              <LongitudeDegrees>139.3909781</LongitudeDegrees>
            </Position>
            <AltitudeMeters>217.0000000</AltitudeMeters>
            <DistanceMeters>7322.3598633</DistanceMeters>
            <Extensions>
              <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2" CadenceSensor="Footpod">
                <Speed>3.4449999</Speed>
              </TPX>
            </Extensions>
          </Trackpoint>
... cont ...

To make sure you have the right points you can also type in the coordinates in Google Maps and check that the pointer ends up at the right place.

Checking the coordinates.

What can be done in this file at this point is to change the <Id> to something unique. In my case I changed it from
<Id>2012-12-18T03:26:14Z</Id>
to
<Id>2012-12-18T03:26:15Z</Id>

Google Maps for the rescue

Now it's time to create the missing values. For this Google Maps is a great tool. What you have to do is to manually plot the missing path, from the point where the straight line starts till it ends. This is done by creating a custom Google Map, where you draw a line where you did run.

Lost data being created.

Having done that you click the "Done" button, then click the "My places" followed by the "Maps" button and you should see your newly created custom map. You should find your new map, which you can right click and copy the link address, that will look something like this:
https://maps.google.com/maps/ms?msa=0&msid=203534381492963346173.0004d11e617ee57d3ca67


Append the following code to the above URL:
&output=kml

The entire URL then looks something like this:
https://maps.google.com/maps/ms?msa=0&msid=203534381492963346173.0004d11e617ee57d3ca67&output=kml

Press enter to load this page, and a .kml file will be downloaded / exported containing the data you just plotted.

Convert
Next step is to convert the downloaded .kml file into Garmin's .tcx format. I found the site gpsies.com for this purpose. Simply upload the .kml file and chose "Garmin Course TCX" as output format.

Modify
Open your new .tcx file in your editor. You need to do some changes. First is to correct the distance. There is a tag named <DistanceMeters>. You should set all the distance meters to a value in between the distance meter recorded just before and just after the gap. In my case I used values from 7320.0000000 to 7320.0000031 as I had 32 track points.

Example:
<DistanceMeters>0.000</DistanceMeters>
was changed to:
<DistanceMeters>7320.0000000</DistanceMeters>

Note: you could calculate and use proper distance, adding the given distance value from the generated maps file to the distance recorded just before the gap. The problem though is that you need to update all following track points as well. That is something you do not want to do by hand.

You might want to update the altitude as well, to avoid a drop to zero. I updated the altitude to:
<AltitudeMeters>164.8000100</AltitudeMeters>
... which was (about) the same as the last registered altitude before the watch was stopped.

Note: You do not need to change the dates / timestamps.

Merge
Now, copy the modified trackpoint data (only the trackpoints) from the google downloaded and converted file and merge it into the gap you found in Garmin's tcx file. You can do this by replacing the <Track></Track> tags.

The new tcx file for me looked like:
... cont ...
          <Trackpoint>
            <Time>2012-12-18T04:23:11Z</Time>
            <Position>
              <LatitudeDegrees>35.7740202</LatitudeDegrees>
              <LongitudeDegrees>139.4144446</LongitudeDegrees>
            </Position>
            <AltitudeMeters>164.8000031</AltitudeMeters>
            <DistanceMeters>7319.4799805</DistanceMeters>
            <Extensions>
              <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2" CadenceSensor="Footpod">
                <Speed>2.4879999</Speed>
              </TPX>
            </Extensions>
          </Trackpoint>
  <Trackpoint>
    <Time>2010-01-01T00:00:00Z</Time>
    <Position>
      <LatitudeDegrees>35.77480300</LatitudeDegrees>
      <LongitudeDegrees>139.4153900</LongitudeDegrees>
    </Position>
    <AltitudeMeters>164.8000100</AltitudeMeters>
    <DistanceMeters>7320.0000000</DistanceMeters>
  </Trackpoint>
...... more generated trackpoints here ....
  <Trackpoint>
    <Time>2010-01-01T00:21:30Z</Time>
    <Position>
      <LatitudeDegrees>35.78354600</LatitudeDegrees>
      <LongitudeDegrees>139.3913730</LongitudeDegrees>
    </Position>
    <AltitudeMeters>164.8000100</AltitudeMeters>
    <DistanceMeters>7320.0000031</DistanceMeters>
  </Trackpoint>
          <Trackpoint>
            <Time>2012-12-18T04:52:44Z</Time>
            <Position>
              <LatitudeDegrees>35.7836677</LatitudeDegrees>
              <LongitudeDegrees>139.3909781</LongitudeDegrees>
            </Position>
            <AltitudeMeters>217.0000000</AltitudeMeters>
            <DistanceMeters>7322.3598633</DistanceMeters>
            <Extensions>
              <TPX xmlns="http://www.garmin.com/xmlschemas/ActivityExtension/v2" CadenceSensor="Footpod">
                <Speed>3.4449999</Speed>
              </TPX>
            </Extensions>
          </Trackpoint>
... cont ...

Upload
Save your file and manually upload it to Garmin connect.


Final tweaks
Your new fixed map will now show up on Garmin Connect.

All good.

Use full edit to set the correct distance (add the distance you found on Google Maps) and the correct time (calculate using the average pace, for example).


You might want to keep the original activity on Garmin Connect. You can do this, without damaging your reports / totals, if you set the activity and event type to something different than for example running and training. I used the values "Other - Special Event".


If there is a tool that does this more automatically let me know. Can you for example do this in SportTracks? I don't know.

If interested, all my activity files, the original and the edited once, including those generated using Google Maps, can be downloaded from here. The original activity can be viewed, along with the corrected activity on Garmin Connect.



keyword: alter change manipulate edit add gps track fix manually wrong right correct garmin 910xt 310xt fixing correcting correct

8 comments:

  1. Svært interressant! Gøy at det går an å gjøre noe manuellt. Imponert over at du klarer å finne ut av det.

    ReplyDelete
    Replies
    1. Takk. Ja, jeg var fornøyd med å klare å manuelt fikse GPS-sporene til denne treningsøkten. Mye skyldes latskap, da jeg ikke orket tanken på å løpe samme runden en gang til.

      Delete
    2. ... for å få riktig GPS-spor.

      Delete
  2. Takk for at du viser hvordan dette kan gjøres.

    Det går an på en annen måte også, men da trengs Google Earth Enterprise.

    ReplyDelete
    Replies
    1. Ah. Om man kan laste inn tcx filen og enkelt endre / legge til punkter der så er jo det en fin løsning ja.

      Delete
  3. I SportTracks fra zonefivesoftware.com kan du gjøre det samme uten kodeklipping. Den importerer *.gpx,*.hrm,*.fitlog,*.pwx,*.bdx,*.csv,*.xml,*.hst,*.tcx og *.fit. Leser også direkte fra Polar, Suunto og Garmin.

    /Knut.Ø

    ReplyDelete
    Replies
    1. Takker for tilbakemelding, Knut!

      Delete

Allowed HTML tags:
<b>bold</b>
<strong>strong</strong>
<i>italics</i>
<em>emphasis</em>
<a href="">hyperlink</a>


Please, show the courtesy of identifying yourself when adding a comment. Anonymous comments will, most likely, be removed.