So I am trying to get the maxspeed for a bounded box, a working example is this[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[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

accept rate: 0%


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.*[maxspeed=][bbox=-106.631425,52.078132,-106.566537,52.146866]


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

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

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.

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.

permanent link

answered 04 Dec '14, 12:14

mmd's gravatar image

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
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 03 Dec '14, 21:49

question was seen: 7,389 times

last updated: 05 Dec '14, 15:16

powered by OSQA