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

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").

  • 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 – Gob Tron Jul 3 '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'] – Gob Tron Jul 3 '16 at 13:35
  • I saw something: Error: Wrong number of parameters ALGORITHM: Convert format INPUT_LAYER <ParameterVector> DEST_FORMAT <ParameterSelection> DEST_DSCO <ParameterString> OUTPUT_LAYER <OutputVector> 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 – Gob Tron Jul 3 '16 at 13:36
  • That makes me think that this algorithm only takes Datasource Creation Options (-dsco), and not Layer Creation Option (-lco) – Gob Tron Jul 3 '16 at 13:37
  • 1
    See my extended answer. – AndreJ Jul 4 '16 at 5:47

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.