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

I have a program that downloads and process GPX tracks from OpenStreetMap using:

http://www.openstreetmap.org/traces/{ID}/data

But how can I find the ID of the latest uploaded GPX file?

Currently I get the ID from:

http://www.openstreetmap.org/traces

But that data is mostly meant to be read by humans, and needs a lot of parsing - is there a better way?

asked 08 Sep '10, 07:15

Johnny%20Carlsen's gravatar image

Johnny Carlsen
91237
accept rate: 0%

2

Your question is fine as it is, but it's very specific. If you can tell us more about what you're trying to do in general, there may be a way of acheiving it without having to scrape the traces page.

(10 Sep '10, 16:23) Jonathan Ben...

Well you can always use the rss feed, just extracting the link element with a regexp will work.

([0-9]*)</link>

e.g

curl http://www.openstreetmap.org/traces/rss |
sed -r 's|.+s/([0-9]+)</link>|\1|;t;d'|
head -1

But compare that to parsing the html page there is almost no gain.

href="/user/[^/]*/traces/([0-9]*)"
href="/edit?gpx=([0-9]*)"

e.g.:

wget -O - "http://www.openstreetmap.org/traces" |
sed '/traces/!d; s|.* href="/user/[^/]*/traces/\([0-9]*\)" .*|http://www.openstreetmap.org/traces/\1/data|;t;d'|
head -1
permanent link

answered 10 Sep '10, 12:08

emj's gravatar image

emj
2.0k123547
accept rate: 15%

edited 11 Sep '10, 00:03

As the API doesn't seem to have a way of retrieving the newest GPX trace ID, here is an example of a shell command to grab the ID from the traces page:

curl -s "http://www.openstreetmap.org/traces" | grep -m 1 "/edit?gpx=" | cut -d "=" -f3 | cut -d "\"" -f1

But of course this might stop working in the future as the layout of the page may change.

permanent link

answered 08 Sep '10, 10:45

scai's gravatar image

scai ♦
33.3k21309459
accept rate: 23%

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:

×290
×255
×2

question asked: 08 Sep '10, 07:15

question was seen: 7,007 times

last updated: 11 Sep '10, 00:03

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