[GIS] Importing extension data from GPX files

gpxqgis

I have a Garmin GPS that does handy things like waypoint averaging which is very useful in my situation where much of my data collection happens under heavy canopy in deep gullies which leads to inaccurate fixes. I often take several samples on different trips to get accurate positions.

The Garmin gpx files have a samples attribute in the extensions and I would like to be able to get this loaded into QGIS so I can have a script update the geometry if the sample number has changed.

here is a sample point with extension data

<wpt lat="-36.599535" lon="174.887440">
  <ele>2499999890505881600000000.000000</ele><time>2017-04-27T00:54:16Z</time><name>TJ B2 1</name>
  <cmt>Track junction in B2</cmt>
  <sym>Flag, Blue</sym>
  <type>Track</type>
  <extensions><wptx1:WaypointExtension><wptx1:Samples>4</wptx1:Samples></wptx1:WaypointExtension></extensions>
</wpt>

to load the file I am using the "add GPX layer" — the old gps tool.

the GPS exposes the files as a USB file system so I am just reading them as files. I can preprocess the files to, say put the sample data into the 'cmt' field but I would rather have a solution in QGIS because I want others to use this.

Best Answer

The "old" GPS tool does not seem to understand the extension tags, maybe it is too old for that.

Instead, use Add vector Layer, but there are still some pitfalls.

If I take a sample of my logger:

<extensions>
 <label xmlns="http://www.topografix.com/GPX/gpx_overlay/0/3">
   <label_text>Push Log Point #1</label_text>
 </label>
</extensions>

I get a field named label with the content <label_text>Push Log Point #1</label_text> (including some trailing blanks).

With your example, I get a field wptx1:WaypointExtension with a content of 0.

Splitting the extension over several lines like

<extensions><wptx1:WaypointExtension>
<wptx1:Samples>4</wptx1:Samples>
</wptx1:WaypointExtension></extensions>

I get a field content of <wptx1:Samples>4</wptx1:Samples>

Removing the wptx1:WaypointExtension like this:

<extensions><wptx1:Samples>4</wptx1:Samples></extensions>

creates a field named wptx1_Samples with a content of 4 (which is probably what you want).

The manpage http://www.gdal.org/drv_gpx.html notes that extensions fields are taken from the first waypoint, so make sure all waypoints have the same extensions.

Alternatively, you can use the OSGEO4W Shell to convert a GPX file to a point shapefile on the command line with:

ogr2ogr --config GPX_USE_EXTENSION YES out1.shp sample1.gpx waypoints
Related Question