gps-wizard

GPS Exchange Format (GPX) - GpsarPro

Background

The GPX home page summarises the importance of GPX validation and best practices. It is very simple and straightforward to ensure the GpsarPro exports are compliant with the GPX 1.0 standard. This document describes how to achieve the goal of GPX compliance / compatibility.

GPX Validation

There are numerous ways to check compliance and validate a GPX file against the XSD. Several approaches are described at the GPX home, but the simplest approach is to use an online validator such as the one at freeformatter.com.

This example has been fixed by hand to ensure compliance with the GPX 1.0 schema. Simply paste it into the XML Validator and press “Validate XML”.

<?xml version="1.0" encoding="ISO-8859-1"?>
<gpx creator="GpsarPro 6.1"
     version="1.0"
     xmlns="http://www.topografix.com/GPX/1/0"
     xmlns:gpsarPro="http://www.gpsactionreplay.com/xml"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.topografix.com/GPX/1/0
                         https://www.topografix.com/GPX/1/0/gpx.xsd
                         http://www.gpsactionreplay.com/xml
                         https://logiqx.github.io/gps-wizard/xmlschemas/logiqx/gpsar/gpsar.xsd">
  <trk>
    <name>no name 1</name>
    <gpsarPro:color>-65536</gpsarPro:color>
    <gpsarPro:nGPS>1</gpsarPro:nGPS>
    <gpsarPro:maxNoDataDuration>60000</gpsarPro:maxNoDataDuration>
    <trkseg>
      <trkpt lat="50.571193" lon="-2.4565465">
        <ele>3.196</ele>
        <time>2023-11-13T13:55:50.200Z</time>
        <course>23.75</course>
        <speed>0.079</speed>
        <sat>12</sat>
        <hdop>2.53</hdop>
        <gpsarPro:satsInView>-1</gpsarPro:satsInView>
      </trkpt>
    </trkseg>
  </trk>
  <gpsarPro:annotations />
</gpx>

Note: The link to https://logiqx.github.io should be replaced with a link to http://www.gpsactionreplay.com once gpsar.xsd is available on the GpsarPro website.

GPX Writer

The above example was based on a GPX file generated by GpsarPro, but a number of changes were required for GPX 1.0 compliance. None of them are particularly complicated but GPX compliance will ensure that exports can be loaded into other applications without issues.

XML Declaration

GpsarPro includes the following declaration:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

The standalone parameter is redundant and it would probably be advisable to use UTF-8 encoding:

<?xml version="1.0" encoding="UTF-8"?>

Obviously, specifying UTF-8 means that the GPX encoding needs to use UTF-8 and not ISO-8859-1.

GPX Schema Location

The xsi:schemaLocation needs to specify the XSD location for the GpsarPro extensions:

<gpx creator="GpsarPro 6.1"
     version="1.0"
     xmlns="http://www.topografix.com/GPX/1/0"
     xmlns:gpsarPro="http://www.gpsactionreplay.com/xml"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.topografix.com/GPX/1/0
                         https://www.topografix.com/GPX/1/0/gpx.xsd
                         http://www.gpsactionreplay.com/xml
                         https://logiqx.github.io/gps-wizard/xmlschemas/logiqx/gpsar/gpsar.xsd">

Notes:

Element Order

GPX 1.0 mandates a strict ordering of elements. The following example does not quite conform with GPX 1.0:

<trkpt lat="50.571193" lon="-2.4565465">
  <ele>3.196</ele>
  <time>2023-11-13T13:55:50.200Z</time>
  <speed>0.079</speed>
  <hdop>2.53</hdop>
  <sat>12</sat>
</trkpt>

The correct element order is shown below, requiring the <sat> element before <hdop>:

<trkpt lat="50.571193" lon="-2.4565465">
  <ele>3.196</ele>
  <time>2023-11-13T13:55:50.200Z</time>
  <speed>0.079</speed>
  <sat>12</sat>
  <hdop>2.53</hdop>
</trkpt>

Note: This change will not affect the GPX reader in any way, but it does affect whether the file is GPX 1.0 compliant.

Course

The <course> element is currently missing from GpsarPro exports, but it would make sense to include it.

The <course> element should appear between the <time> and <speed> elements.

<trkpt lat="50.571193" lon="-2.4565465">
  <ele>3.196</ele>
  <time>2023-11-13T13:55:50.200Z</time>
  <course>23.75</course>
  <speed>0.079</speed>
  <sat>12</sat>
  <hdop>2.53</hdop>
</trkpt>

Note: The GPX reader should also be tweaked to recognise the <course> element in GPX files.

Color

The GPX exports of GpsarPro include a “color” element:

<color>-65536</color>

The <color> element is not part of the GPX 1.0 schema, so it needs to use the gpsarPro namespace:

<gpsarPro:color>-65536</gpsarPro:color>

Note: The GPX reader should support both <color> and <gpsarPro:color> to ensure backwards compatibility.

Track Extensions

GPX files generated by GpsarPro include some custom elements after the <trkseg> element(s):

<trk>
  <name>no name 1</name>
  <trkseg>
    ...
  </trkseg>
  <color>-65536</color>
  <gpsarPro:nGPS>1</gpsarPro:nGPS>
  <gpsarPro:maxNoDataDuration>60000</gpsarPro:maxNoDataDuration>
</trk>

These elements need moving above the <trkseg> element(s). Also note the use of gpsarPro for <color>:

<trk>
  <name>no name 1</name>
  <gpsarPro:color>-65536</gpsarPro:color>
  <gpsarPro:nGPS>1</gpsarPro:nGPS>
  <gpsarPro:maxNoDataDuration>60000</gpsarPro:maxNoDataDuration>
  <trkseg>
    ...
  </trkseg>
</trk>

Note: This change will not affect the GPX reader in any way, but it does affect whether the file is GPX 1.0 compliant.

Formatting

The original GPX export from GpsarPro does not make use of any indentation:

<trk>
<name>no name 1</name>
<trkseg>
<trkpt lat="50.571193" lon="-2.4565465"><ele>3.196</ele><time>2023-11-13T13:55:50.200Z</time>
<speed>0.079</speed>
<hdop>2.53</hdop>
<sat>12</sat>
<gpsarPro:satsInView>-1</gpsarPro:satsInView></trkpt>
<trkpt lat="50.5712273" lon="-2.456548"><ele>4.08</ele><time>2023-11-13T15:47:14Z</time>
<speed>0.014</speed>
<hdop>0.875</hdop>
<sat>24</sat>
<gpsarPro:satsInView>-1</gpsarPro:satsInView></trkpt>
</trkseg>
<color>-65536</color>
<gpsarPro:nGPS>1</gpsarPro:nGPS>
<gpsarPro:maxNoDataDuration>60000</gpsarPro:maxNoDataDuration>
</trk>

It would be beneficial to use two spaces for indentation, making the GPX file much more readable:

  <trk>
    <name>no name 1</name>
    <gpsarPro:color>-65536</gpsarPro:color>
    <gpsarPro:nGPS>1</gpsarPro:nGPS>
    <gpsarPro:maxNoDataDuration>60000</gpsarPro:maxNoDataDuration>
    <trkseg>
      <trkpt lat="50.571193" lon="-2.4565465">
        <ele>3.196</ele>
        <time>2023-11-13T13:55:50.200Z</time>
        <course>23.75</course>
        <speed>0.079</speed>
        <sat>12</sat>
        <hdop>2.53</hdop>
        <gpsarPro:satsInView>-1</gpsarPro:satsInView>
      </trkpt>
      <trkpt lat="50.5712273" lon="-2.456548">
        <ele>4.08</ele>
        <time>2023-11-13T15:47:14Z</time>
        <course>21.75</course>
        <speed>0.014</speed>
        <sat>24</sat>
        <hdop>0.875</hdop>
        <gpsarPro:satsInView>-1</gpsarPro:satsInView>
      </trkpt>
    </trkseg>
  </trk>

GPX Reader

Speed

The GPX reader should be able to recognise the following variations of SOG.

The namespaces would be as follows:

xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0"
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v2"
xmlns:ns3="http://www.garmin.com/xmlschemas/TrackPointExtension/v2

Note: Technically speaking the namespace prefix (e.g. gpxdata, gpxtpx or ns3) can be chosen by the GPX creator.

Course

The GPX reader should be able to recognise the following variations of COG.

The namespaces would be as follows:

xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v2"
xmlns:ns3="http://www.garmin.com/xmlschemas/TrackPointExtension/v2

Note: Technically speaking the namespace prefix (e.g. gpxtpx or ns3) can be chosen by the GPX creator.

Summary

Ensuring the exports of GpsarPro are compliant with GPX 1.0 is pretty straightforward: