1

I am trying to use the following query to get all buildings from the given area in OSM with the Overpass Api, but I am receiving an "Received corrupt data from Overpass (incomplete polygon)" Error. Where is the error in my query?

import overpass
api = overpass.API()

query = """
[out:json][timeout:25];
(way["building"](47.35436014253597,8.490386538763183,47.39245772996116,8.57950135269201);
relation["building"](47.35436014253597,8.490386538763183,47.39245772996116,8.57950135269201);
);
out body;
>;
out skel qt;
"""

response = api.get(query)
0

I've also tried an approach with requests. The issue is not in the http call but when parsing the response. overpass does like requests (make http call) but also parses the content to use it directly. The parsing does not happen well. It could be a bug and you should open an issue at https://github.com/mvexel/overpass-api-python-wrapper/ as it seems GeoJSON support for relation in the library is not perfect e.g https://github.com/mvexel/overpass-api-python-wrapper/issues/48

I've taken another approach combining requests and another lib called osmtogeojson to do the same as overpass library

import requests
from osmtogeojson import osmtogeojson

# Should use [out:json] in the query as later osmtogeojson does not parse XML
query = """
[out:json][timeout:25];
(way["building"](47.35436014253597,8.490386538763183,47.39245772996116,8.57950135269201);
relation["building"](47.35436014253597,8.490386538763183,47.39245772996116,8.57950135269201);
);
out body;
>;
out skel qt;
"""

url = "http://overpass-api.de/api/interpreter"
r = requests.get(url, params={'data': query})

result = osmtogeojson.process_osm_json(r.json())
1
  • thanks, I was aware of the requests solution but the combination with osmtogeojson is exactly what I needed!
    – emily
    May 17 '20 at 20:07
0

I tried running your query in Overpass and in Python (using requests instead of overpass) and it runs fine. Here is the code I used:

import requests

query = """
[out:json][timeout:25];
(way["building"](47.35436014253597,8.490386538763183,47.39245772996116,8.57950135269201);
relation["building"](47.35436014253597,8.490386538763183,47.39245772996116,8.57950135269201);
);
out body;
>;
out skel qt;
"""

url = "http://overpass-api.de/api/interpreter"
r = requests.get(url, params={'data': query})

print(len(r.json()['elements']))
# 165715

print(r.json()['elements'][0])
# {'type': 'way', 'id': 4592724, 'nodes': [29039246, 29039249, 29033199, 29039253, 29039246], 'tags': {'addr:housenumber': '34', 'addr:street': 'Rotwandstrasse', 'building': 'yes'}}

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.