3

So I am trying to convert a LineString shapefile into GPX using the 'gdalogr:ogr2ogr' algorithm in a QGIS python plugin.

The problem is that I alway get routes instead of tracks, even if I specify the option 'FORCE_GPX_TRACK=YES'. The input is actually a LineString, not a MultiLineString (by default, LineString are created into the route layer). But the 'FORCE_GPX_TRACK' option is supposed to create it as a track...

Here is the code:

processing.runalg("gdalogr:ogr2ogr",inputf,16,'FORCE_GPX_TRACK=YES',self.GUIControl.output_path + os.sep + "GPX" + os.sep + filename)

EDIT:

Maybe I should mention that I am trying this on QGIS 2.4 on Linux (debian)

I tried 'gdalogr:convertformat' on QGIS 2.12 on Windows and it wrote the GPX file with the correct geometries, as tracks. But, there are no attributes though. Maybe I should use '-select field_list' option after -lco ?

I will try it tommorrow, because i'm on my windows machine right now. I just wanted to post an update of my problem to let you know i'm still alive :P

TurboGraphxBeige
  • 1,467
  • 10
  • 24
  • For the attributes, you need -dsco GPX_USE_EXTENSIONS=YES. See http://gis.stackexchange.com/questions/40731/how-to-convert-shp-into-gpx-using-qgis – AndreJ Jul 11 '16 at 05:43
  • See AndreJ's answer. It didn't work in QGIS 2.4, but it does in 2.8 (both in linux). – TurboGraphxBeige Jul 26 '16 at 23:54

1 Answers1

3

In ogr2ogr you have dataset creation options, and layer creation options. According to http://www.gdal.org/drv_gpx.html, FORCE_GPX_TRACK=YES is a LAYER creation option.

So you have to add -lco "FORCE_GPX_TRACK=YES" to get the tracks instead of routes.

This works for the command line version just the same.

Make sure the data is in EPSG:4326.


The above runs fine in the processing toolbox. You can look inside the logfile under C:\Users\<username>\.qgis2\processing\processing.log to see the executed command:

08:47:59|processing.runalg("gdalogr:convertformat","<input-shapefile>",16,"-lco FORCE_GPX_TRACK=YES","<output-gpxfile")

So I suggest to use gdalogr:convertformat instead of gdalogr:ogr2ogr. See http://docs.qgis.org/2.8/en/docs/user_manual/processing_algs/gdalogr/ogr_conversion.html#convert-format for the documentation, or processing.alghelp("gdalogr:convertformat").

AndreJ
  • 76,698
  • 5
  • 86
  • 162
  • I tried to add "-lco" before, but I still get routes instead of tracks:

    processing.runalg("gdalogr:ogr2ogr", inputf[0], 16, "-lco FORCE_GPX_TRACK=YES", self.GUIControl.output_path + os.sep + "GPX" + os.sep + filename)

    Am i doing something wrong? It works when using "Save As..." in QGIS though. So I guess it's not a driver version issue or something

    – TurboGraphxBeige Jul 03 '16 at 13:15
  • I also tried 'lco FORCE_GPX_TRACK=YES', ['-lco FORCE_GPX_TRACK=YES'], ['lco FORCE_GPX_TRACK=YES'], ['FORCE_GPX_TRACK=YES'] – TurboGraphxBeige Jul 03 '16 at 13:35
  • I saw something:

    Error: Wrong number of parameters ALGORITHM: Convert format INPUT_LAYER DEST_FORMAT DEST_DSCO OUTPUT_LAYER

    DEST_FORMAT(Destination Format) 0 - ESRI Shapefile 1 - GeoJSON 2 - GeoRSS 3 - SQLite 4 - GMT 5 - MapInfo File 6 - INTERLIS 1 7 - INTERLIS 2 8 - GML 9 - Geoconcept 10 - DXF 11 - DGN 12 - CSV 13 - BNA 14 - S57 15 - KML 16 - GPX 17 - PGDump 18 - GPSTrackMaker 19 - ODS 20 - XLSX 21 - PDF

    – TurboGraphxBeige Jul 03 '16 at 13:36
  • That makes me think that this algorithm only takes Datasource Creation Options (-dsco), and not Layer Creation Option (-lco) – TurboGraphxBeige Jul 03 '16 at 13:37
  • 1
    See my extended answer. – AndreJ Jul 04 '16 at 05:47