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

So I am trying to get the maxspeed for a bounded box, a working example is this www.overpass-api.de/api/xapi?[maxspeed=][bbox=-106.631425,52.078132,-106.566537,52.146866]

However I am unable to get a JSON out of it. I have used the other way that is overpass ql like this http://overpass-api.de/api/interpreter?data=[out:json];(node(52.078132,-106.631425,52.146866,-106.566537);<;);out body;

However the data returned isnt as consistent as I would like. Sometimes overpass ql returns the right data and sometimes it doesnt, while as xapi provides more consistency. Is there a way to get JSON using xapi ?

asked 03 Dec '14, 21:49

klk's gravatar image

klk
11112
accept rate: 0%

1

Can you describe what exactly about the data isn't consistent?

(04 Dec '14, 10:05) scai ♦

For the bbox set of points, the overpass ql query did not spit out any information. While as when I used xapi there was data for those points. I thought they were accessing the same database.

(04 Dec '14, 18:20) klk

First of all: XAPI does not support JSON at all. The follow answer will help you to create an equivalent Overpass XML / QL query which comes with JSON output. Use it as a replacement of your current XAPI query.

If you prepend your XAPI query with "debug=", you can see the actual Overpass XML representation of the XAPI query. We use this as a starting point to create an equivalent query which returns JSON instead of XML. BTW: Internally, your XAPI query is converted into exactly this format before is it being executed by overpass api.

http://www.overpass-api.de/api/xapi?debug=*[maxspeed=][bbox=-106.631425,52.078132,-106.566537,52.146866]

Result:

<query type="node">
  <bbox-query s="52.078132" n="52.146866" w="-106.631425" e="-106.566537"/>
  <has-kv k="maxspeed" v=""/>
</query>
<union>
  <item/>
  <query type="way">
    <bbox-query s="52.078132" n="52.146866" w="-106.631425" e="-106.566537"/>
    <has-kv k="maxspeed" v=""/>
  </query>
  <recurse type="way-node"/>
</union>
<print/>
<query type="relation">
  <bbox-query s="52.078132" n="52.146866" w="-106.631425" e="-106.566537"/>
  <has-kv k="maxspeed" v=""/>
</query>
<print/>

Now, we need to tell Overpass API to return the result in JSON format. This can be achieved by adding an osm-script header with a dedicated output attribute:

<osm-script output="json">
...
</osm-script>

If you run this query, you will get exactly the same date as per your XAPI query, now with JSON format output. Try this in overpass turbo. http://overpass-turbo.eu/s/6nr

If you favor Overpass QL format, you can easily convert your Overpass XML query by clicking on Export -> Query -> Overpass QL in overpass turbo. That's how this would look like.

[out:json]
;
node
  (52.078132,-106.631425,52.146866,-106.566537)
  ["maxspeed"];
(
  ._;
  way
    (52.078132,-106.631425,52.146866,-106.566537)
    ["maxspeed"];
  node(w);
);
out;
relation
  (52.078132,-106.631425,52.146866,-106.566537)
  ["maxspeed"];
out;
permanent link

answered 04 Dec '14, 12:14

mmd's gravatar image

mmd
5.7k15388
accept rate: 37%

edited 05 Dec '14, 15:14

when I have read the question right, he is looking for the RESULT in JSON format, and not the query itself, isn't it?

(05 Dec '14, 14:40) stephan75

@stephan75: xapi is unable to produce JSON. My answer will help you to create an equivalent Overpass XML/QL query, which in fact returns the same result in JSON format.

(05 Dec '14, 15:15) mmd

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:

×483
×85
×65
×32

question asked: 03 Dec '14, 21:49

question was seen: 8,299 times

last updated: 05 Dec '14, 15:16

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