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.

Steve Bennett
  • 5,682
  • 2
  • 44
  • 69

2 Answers2

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'
Nathan W
  • 34,706
  • 5
  • 97
  • 148
  • 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 04 '13 at 05: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.

AndreJ
  • 76,698
  • 5
  • 86
  • 162