1

I am new to OSM.

When I make an API bounding box call like below:

import overpass

# bounding box coordinates
min_long = min(longs)
min_lat = min(lats)
max_long = max(longs)
max_lat = max(lats)

# query overpass within OpenStreetMap
api = overpass.API()
map_query = overpass.MapQuery(min_lat,min_long,max_lat,max_long)
response = api.Get(map_query)

The output is not wrapped. Here is a sample when I print response:

<member type="way" ref="50345468" role=""/>
<member type="way" ref="119882166" role=""/>
<member type="way" ref="7664653" role=""/>
<member type="way" ref="7661912" role=""/>
<member type="way" ref="7662660" role=""/>
<member type="way" ref="6983960" role=""/>
<member type="way" ref="6975837" role=""/>
<member type="way" ref="6982355" role=""/>
<member type="way" ref="6983849" role=""/>

Anybody have an idea of what is going on here?

  • Hello Joseph, welcome to GIS.SE. I don't know overpass in detail, but from what I can see, the API is returning the results directly. What kind of wrapper were you expecting? something like <results><foo></results/>? – George Silva Feb 16 '16 at 16:09
  • Hi @George! I am expecting something like this. A set of dictionaries that are python readable. – Joseph Gutenson Feb 16 '16 at 16:19
  • crosspost: help.openstreetmap.org/questions/48174/… – scai Feb 16 '16 at 18:27
3

Turns out the pip installation of the Python Overpass API is different than the current version on github. If anyone else encounters this problem, just install the github version instead.

| improve this answer | |
  • This pretty much suck, maybe they forgot to add the latest version to PyPI? – George Silva Feb 19 '16 at 17:14
0

this is pretty weird. according to the docs, the default response is already in that form, hence this example:

print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]

what are the versions that you are using? any chance that you might be using an older version of overpass python API and they changed the default response?

There is an argument, when making the request, which can control the type of response (xml or geojson).

Check the version using

pip freeze

or if you're not using a virtualenv, check the folder where overpass is installed and poke around.

| improve this answer | |
  • I'm using 0.3.1 which from github looks to be the latest version. I believe that response variable that the api call returns is in xml instead of a Python dictionary. – Joseph Gutenson Feb 16 '16 at 18:20
  • The docs state otherwise. There is a param, called "responseformat", that can be "xml" or "geojson". Check the code here: github.com/mvexel/overpass-api-python-wrapper/blob/master/… the default is geojson. You might want to try to use the DEBUG mode to get more information... – George Silva Feb 16 '16 at 18:53
0

Overpass API supports different file formats (currently XML, JSON and CSV). According to a quick search you seem to be using Overpass API python wrapper. The README explains that you can call Get() with a responseformat parameter for choosing the file format. So try calling api.Get(map_query, responseformat="json").

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.