Hello, can anyone point me in the direction of how one might be able to extract OSM feature information from a GPX file. For example, I would like to determine all the peaks that may have been summited on a GPS track.

asked 06 Sep '18, 22:56

ClarionRunner's gravatar image

accept rate: 0%

edited 14 Sep '18, 21:36

aseerel4c26's gravatar image

aseerel4c26 ♦

Do you think of adding these peaks to OSM (contribution) or do you think of, instead, querying the OSM data for nearby peaks (possibly with name infomation) (usage)?

(08 Sep '18, 19:58) aseerel4c26 ♦

the latter querying the OSM data for nearby peaks

(08 Sep '18, 20:05) ClarionRunner

The Overpass API around filter queries for elements within a given radius (in meters) along a linestring when given a list of lat/lon pairs:


For example (in Overpass Turbo):

out meta;


There might be better ways, but here is a one-liner for the Linux/Ubuntu command-line to convert a GPX track to the expected linestring format:

ogr2ogr -f CSV /vsistdout/ brouter.gpx tracks -lco GEOMETRY=AS_WKT -simplify 0.001 | \
tail -n +2 | \
sed -e 's/.* (\+\([^)]*\))\+".*/\1/' -e 's/\([0-9\.]*\) \([0-9\.]*\),\?/\2,\1,/g' -e 's/,$//'
  • example GPX track created using an online router
  • uses GDAL ogr2ogr converter (requires gdal-bin package)
    with GPX and CSV with WKT (Well-known Text) formats, as this comes close to expected format
  • outputs to console with "/vsistdout/"
  • "simplify" reduces number of nodes, distance tolerance in degrees, 0.00001° about 1 meter, depending on latitude
  • "tail" skips csv header
  • "sed" extracts coordinates, flips lon/lat and uses all comma, removes trailing comma
permanent link

answered 14 Sep '18, 20:39

ikonor's gravatar image

accept rate: 21%

edited 14 Sep '18, 20:43

Thank you so much!!!! Just what I was looking for :)

(17 Sep '18, 07:05) ClarionRunner

how would I pass this query to https://www.overpass-api.de/api/interpreter from a php file?

(17 Sep '18, 07:58) ClarionRunner

The custom shortcut "{{latlons}}" only works in Overpass Turbo. Elsewhere, you need to replace it yourself. You can get an interpreter URL from Overpass Turbo with Export > Data > raw data from Overpass API interpreter: https://wiki.openstreetmap.org/wiki/Overpass_turbo#Data Or use a POST request, see https://overpass-api.de/command_line.html

(17 Sep '18, 08:42) ikonor
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 06 Sep '18, 22:56

question was seen: 1,800 times

last updated: 17 Sep '18, 08:42

powered by OSQA