1
1

I'm am on a project that would like to obtain the GPS boundaries of objects/locations of interest in JSON format. We have found it possible to make a single API call to http://overpass-api.de/api/interpreter? to get a list of ways with node ID's. We then found that we could traverse the list and make another API call to https://api.openstreetmap.org/api/0.6/node/{nodeID}.json to obtain the individual node coordinates. Is there a more efficient process in retrieving this information as some ways could have up to 2000 nodes? Thanks for the information in advance!

asked 27 Jan, 01:34

nonProfitDeveloper's gravatar image

nonProfitDev...
31113
accept rate: 0%


Overpass-API has functionality to retrieve the nodes: https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Recurse_down_.28.3E.29

Typically you'd do something like

(way[...];
>;
);
out;

where the way[...]; is what you are doing to find the ways, and then >; adds the results to the union.

permanent link

answered 27 Jan, 02:06

maxerickson's gravatar image

maxerickson
12.5k1079175
accept rate: 31%

Thank you, I was not aware of the recurse down feature.

(19 Feb, 02:57) nonProfitDev...

Have you looked at my answer, which shows better ways to get just the coordinates, if you're not interested in the node objects?

(19 Feb, 07:00) ikonor

You can retrieve a way and all of its nodes directly from the OSM API:

https://www.openstreetmap.org/api/0.6/way/1010/full

However keep in mind that this API is primarily for editing OSM data. Don't perform bulk requests against it.

permanent link

answered 27 Jan, 08:41

scai's gravatar image

scai ♦
32.4k20296448
accept rate: 23%

Beside recurse down (>), Overpass API offers additional options to resolve the node references of a way and to get the coordinates of the nodes:

out geom

Using out geom output:

[out:json];
way(95777558);
out geom;

writes the node coordinates to an additional geometry property in the way object:

"geometry": [
  { "lat": 44.4198143, "lon": 38.2052864 },
  { "lat": 44.4196878, "lon": 38.2052733 },
  { "lat": 44.4195565, "lon": 38.2052576 }
],

No need to include the full node objects in the result.

GeoJSON format

Using the Geometry operator geom() in a convert statement:

[out:json];
way(95777558);
convert item ::=::,::geom=geom(),_osm_type=type();
out geom;

converts the way object into a derived object with the given properties and writes the coordinates into the geometry property in the GeoJSON format:

"geometry": {
  "type": "LineString",
  "coordinates": [
    [38.2052864, 44.4198143],
    [38.2052733, 44.4196878],
    [38.2052576, 44.4195565]
  ]
},

See also:

permanent link

answered 28 Jan, 19:58

ikonor's gravatar image

ikonor
1.2k2917
accept rate: 21%

edited 28 Jan, 20:05

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:

×73
×22

question asked: 27 Jan, 01:34

question was seen: 503 times

last updated: 19 Feb, 07:00

powered by OSQA