2

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.

1

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
  • Thanks Andre! I will almost certainly end up preprocessing my gpx files but it is really useful to know that 'add vector layer' can handle extension, even if it is a bit simple minded. I will try using that instead of the old GPSTOOL – Russell Fulton May 1 '17 at 20:30
  • You might as well take a look at stackoverflow.com/questions/18071387/… and stackoverflow.com/questions/36871829/… for programmatical solutions. – AndreJ May 2 '17 at 5:28
  • I have just found a "gotcha" with using "add vector layer" with GPX files. It creates 3D geometry and when I try and add these points into my PostGIS tables I get errors about the mismatched geometry. I also get errors when I if I save the files to spatialite telling it to ignore 'z' in the geometry option. – Russell Fulton May 7 '17 at 5:29
  • The ele value you privided does not make sense. It might help to use ogr2ogr with --config GPX_ELE_AS_25D NO. – AndreJ May 7 '17 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.