1

When I do "save as gpx", it creates a gpx file with waypoints only, although I force route and track. Besides other non-gpx schema columns all relavant gpx columns exist based on a attribute table merge of a 'gpx to point shapefile' layer and 'custom point shapefile' layer.

  • What software are you using? – AndreJ Jan 14 '18 at 6:39
  • QGIS, version 2.8.15 – Stefan Jan 14 '18 at 8:40
  • I believe that the point layer must have a special structure for making it possible to create the tracks and routes gdal.org/drv_gpx.html – user30184 Jan 14 '18 at 11:49
  • is there any example around? – Stefan Jan 14 '18 at 13:46
  • Did you use the GPS Tools icon, or Save As ...? – AndreJ Jan 15 '18 at 7:08
1

http://www.gdal.org/drv_gpx.html

Starting with GDAL/OGR 1.8.0, if a layer is named "track_points" with wkbPoint/wkbPoint25D geometries, the tracks in the GPX file will be built from the sequence of features in that layer. This is the way of setting GPX attributes for each track point, in addition to the raw coordinates. Points belonging to the same track are identified thanks to the same value of the 'track_fid' field (and it will be broken into track segments according to the value of the 'track_seg_id' field). They must be written in sequence so that track objects are properly reconstructed. The 'track_name' field can be set on the first track point to fill the element of the track. Similarly, if a layer is named "route_points" with wkbPoint/wkbPoint25D geometries, the routes in the GPX file will be built from the sequence of points with the same value of the 'route_fid' field. The 'route_name' field can be set on the first track point to fill the element of the route.

You can find from the GDAL autotest suite an example how to create a point layer that can be used for constructing routes. It is a Python script but the idea matters, not the method. See file https://trac.osgeo.org/gdal/browser/trunk/autotest/ogr/ogr_gpx.py starting from line 436.

feat = ogr.Feature(lyr.GetLayerDefn())
geom = ogr.CreateGeometryFromWkt('POINT(2 49)')
feat.SetField('route_name', 'ROUTE_NAME')
feat.SetField('route_fid', 0)
feat.SetGeometry(geom)
lyr.CreateFeature(feat)

feat = ogr.Feature(lyr.GetLayerDefn())
geom = ogr.CreateGeometryFromWkt('POINT(3 50)')
feat.SetField('route_name', '--ignored--')
feat.SetField('route_fid', 0)
feat.SetGeometry(geom)
lyr.CreateFeature(feat)

feat = ogr.Feature(lyr.GetLayerDefn())
geom = ogr.CreateGeometryFromWkt('POINT(3 51)')
feat.SetField('route_name', 'ROUTE_NAME2')
feat.SetField('route_fid', 1)
feat.SetGeometry(geom)
lyr.CreateFeature(feat)

feat = ogr.Feature(lyr.GetLayerDefn())
geom = ogr.CreateGeometryFromWkt('POINT(3 49)')
feat.SetField('route_fid', 1)
feat.SetGeometry(geom)
lyr.CreateFeature(feat)

You must add an integer attribute "route_fid" into your point layer and insert the same number for all points which belong to the same route. If you want to give a name for your route, insert also a string attribute "route_name". If you can't manage to do the conversion with QGIS have a try with GDAL

ogr2ogr -f gpx my_route.gpx my_points_with_route_fids.shp
  • is there any example for QGIS around otherwise it will quite and trial and error thing. I'm not familiar with GDAL. – Stefan Jan 15 '18 at 19:53
  • Try with QGIS then. Add field "route_id" and see what happens. QGIS does quite many things internally with GDAL. – user30184 Jan 15 '18 at 20:28

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.