3

I have a request to provide GPX files of certain trails (around 100) that are present in OpenStreetMap. Given a local PostGIS install with OSM data, I think the process would be something like:

  1. Define query to select the correct features, with appropriate metadata
  2. Extract those features as shapefiles
  3. Convert the shapefiles to GPX

Is this on the right track? Would a different format (KML, GeoJSON...) be better?

If this is the right way:

Step 1: Straightforward enough, I think.

Step 2: Using ogr2ogr with the postgis option? (eg http://www.bostongis.com/PrinterFriendly.aspx?content_name=ogr_cheatsheet)

Step 3: The only command line tool I could find, shp2gpx, doesn't seem to be available for download. Is there something else that could do the job?

Just wanted to check whether this is a sensible approach, and that there isn't an easier way, before I dive in.

2 Answers 2

2

Why not skip the whole shapefile step and extract them to GPX using ogr2ogr

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

ogr2ogr -f GPX output.gpx PG:'host=yourserver user=youruser dbname=yourdb'
1
  • 2
    Not as simple as that. In most cases, you need -lco FORCE_GPX_TRACK=YES to ensure that you get a track and not a route GPX. Furthermore -dsco GPX_USE_EXTENSIONS=YES is needed because GPX only allows a small bunch of field names. Otherwise you get stuck with error messages.
    – AndreJ
    Jul 4, 2013 at 5:37
2

I would suggest to load the postgis database as a layer into QGIS with OSM via Openlayers plugin as background, and select the features you want graphically or with a query. Then you can use Save as... to write a GPX file.

In most cases, you need FORCE_GPX_TRACK=YES in the layer creation options field to ensure that you get a track and not a route GPX. Furthermore GPX_USE_EXTENSIONS=YES in data creation options or checking Surpress attibute creation is needed because GPX only allows a small bunch of field names. Otherwise you get stuck with error messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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