NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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

ClarionRunner's gravatar image

ClarionRunner
26112
accept rate: 0%

edited 14 Sep '18, 21:36

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554

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:

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

ikonor's gravatar image

ikonor
1.3k21119
accept rate: 18%

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
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 '18, 08:42) ikonor

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:

×255
×147
×104
×10
×8

question asked: 06 Sep '18, 22:56

question was seen: 3,999 times

last updated: 17 Sep '18, 08:42

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum