0
1

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, 22:56

ClarionRunner's gravatar image

ClarionRunner
1112
accept rate: 0%

edited 14 Sep, 21:36

aseerel4c26's gravatar image

aseerel4c26 ♦
31.1k15232531

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, 19:58) aseerel4c26 ♦

the latter querying the OSM data for nearby peaks

(08 Sep, 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:

(around:radius,latitude_1,longitude_1,latitude_2,longitude_2,...,latitude_n,longitude_n)

For example (in Overpass Turbo):

node[natural=peak](around:500,{{latlons}});
(._;>;);
out meta;

{{latlons=47.492131,10.072515,47.497647,10.084685,47.497754,10.089965,47.502135,10.097873,47.502383,10.104472,47.504251,10.106848,47.504002,10.118661,47.510921,10.13158,47.510898,10.146653,47.517277,10.160911,47.516576,10.164531,47.520637,10.181296,47.528658,10.1929,47.531326,10.202335,47.530947,10.207266,47.537454,10.217361}}

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, 20:39

ikonor's gravatar image

ikonor
1.0k2814
accept rate: 30%

edited 14 Sep, 20:43

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

(17 Sep, 07:05) ClarionRunner

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

(17 Sep, 07:58) ClarionRunner
1

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, 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

By RSS:

Answers

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:

×212
×105
×83
×7
×6

question asked: 06 Sep, 22:56

question was seen: 236 times

last updated: 17 Sep, 08:42

powered by OSQA