Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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'
share|improve this answer
1  
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 '13 at 5:37

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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