• Resolved kabouton

    (@kabouton)


    You previously suggested I send a copy of my gpx. This is an output from Garmin where they have included their various gpx extensions. It fails your ‘upload gpx’ validation and this is one thing that has me stumped and unable to correct. I think it has soomething to do with the multiple namesspaces. Also their pointer to the topografix xsd is wrong!?
    If you have any suggestions how I could fix this, I could make changes in my local files until you have a revision out.
    Thanks
    Katherine

    <?xml version="1.0" encoding="UTF-8"?>
    <gpx creator="Garmin Connect" version="1.1"
      xsi:schemaLocation="https://www.topografix.com/GPX/1/1 https://www.topografix.com/GPX/11.xsd"
      xmlns:ns3="https://www.garmin.com/xmlschemas/TrackPointExtension/v1"
      xmlns="https://www.topografix.com/GPX/1/1"
      xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="https://www.garmin.com/xmlschemas/GpxExtensions/v3">
      <metadata>
        <link href="connect.garmin.com">
          <text>Garmin Connect</text>
        </link>
        <time>2014-09-25T14:24:43.000Z</time>
      </metadata>
      <trk>
        <name>Walking back</name>
        <type>walking</type>
        <trkseg>
          <trkpt lat="51.5005199611186981201171875" lon="-0.1937947981059551239013671875">
            <ele>20.799999237060546875</ele>
            <time>2014-09-25T14:24:44.000Z</time>
            <extensions>
              <ns3:TrackPointExtension/>
            </extensions>
          </trkpt>
          <trkpt lat="51.5005199611186981201171875" lon="-0.1937947981059551239013671875">
            <ele>20.799999237060546875</ele>
            <time>2014-09-25T14:24:45.000Z</time>
            <extensions>
              <ns3:TrackPointExtension/>
            </extensions>
          </trkpt>
        </trkseg>
      </trk>
    </gpx>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kabouton

    (@kabouton)

    I finally sat down to try to figure this out for myself. Took me a few days but now is the time I guess.

    First I discovered it fails because Garmin exports their gpx lat/lon with 25 decimal point precision!!! What!! And PHP LibXML doesn’t like that (it doesn’t want more than 19 or something like that)

    So I wrote an xslt file to transform the garmin export gpx, shortening both the lat and lon to decimal precision to 7. Note the use of the gpx namespace. (This took me a while)

    <xsl:stylesheet version="1.0" xmlns:xsl="https://www.w3.org/1999/XSL/Transform" xmlns:gpx="https://www.topografix.com/GPX/1/1">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="gpx:trkpt/@lat">
            <xsl:attribute name="lat">
             <xsl:value-of select="format-number(number(),'0.0000000')" />
            </xsl:attribute>
        </xsl:template>
    <xsl:template match="gpx:trkpt/@lon">
            <xsl:attribute name="lon">
             <xsl:value-of select="format-number(number(),'0.0000000')" />
            </xsl:attribute>
        </xsl:template>
    <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>

    I then changed class-trackserver.php function validate_gpx_file($filename) around Line 2935 to take the incoming gpx file, see if it is creator=Garmin Connect and if it is then transform the gpx using the xslt and use that as the new xml file to import.

    function validate_gpx_file( $filename ) {
    	$xml = new DOMDocument();
    	$xml->load( $filename );		
    	/*
    	 * KAB
    	 * Garmin exports their lat/lon gpx with 28 decial point precision!!
    	 * PHP can't handle it. So write a xslt to transform it to 7 decimal points
    	 * 
    	 */
    	$creator = $xml->documentElement->getAttribute('creator');
    	if ($creator == "Garmin Connect") {	
    		$xslt_file = plugin_dir_path( __FILE__ ) . '/garmin-gpx.xslt';
    		$stylesheet = new DOMDocument; 
    		$stylesheet->load($xslt_file);
    		$xsl = new XSLTProcessor();			
    		$xsl->importStylesheet( $stylesheet );
    		if($output = $xsl->transformToXML($xml)) {
    			file_put_contents('transformed.xml', $output);	
    			$xml = new DOMDocument();
    			$xml->load( 'transformed.xml' );
    		} 
    	} 
    	return $this->validate_gpx_data( $xml);				
    }

    Seems to have solved the problem for me. It imports without a GPX1.1 validation error, and displays on the map as it should.
    Someone might find this useful.

    Brilliant!
    Thank you @kabouton
    I followed your steps and it worked for me too! This should be documented as a fix as I would guess there would be more users using Garmin Connect GPX exports with this Plugin

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘failing validation’ is closed to new replies.