osm-python-tools icon indicating copy to clipboard operation
osm-python-tools copied to clipboard

Overpass returns every way twice

Open TheFGFSEagle opened this issue 2 years ago • 6 comments

I was trying to find all runways within a bounding box, and noticed that I get every runway (mapped as a way with aeroway=runway) twice. Here's a test code:

from OSMPythonTools import overpass
query = overpass.overpassQueryBuilder(bbox=[-6.05, 144.95, -6, 145], elementType="way",
                                                                 selector='"aeroway"="runway"', out="body", includeCenter=True)
result = overpass.Overpass().query(query).ways()
for e in result:
    print(e, e.tags())

which prints:

[overpass] downloading data: [timeout:25][out:json];(way["aeroway"="runway"](-6.05,144.95,-6,145);); out center; out body;
<OSMPythonTools.element.Element object at 0x7fb7a11704c0> {'aeroway': 'runway', 'ele': '1516', 'length': '1015', 'name': '03/21', 'source': 'Bing', 'surface': 'paved'}
<OSMPythonTools.element.Element object at 0x7fb7a11700d0> {'aeroway': 'runway', 'ele': '1516', 'length': '1015', 'name': '03/21', 'source': 'Bing', 'surface': 'paved'}

You can see that I got two different Elements holding the exact same data. Here's the test area in OSM And Overpass-turbo shows that there is in fact only one way tagged ´aeroway=runway´ in that area.

TheFGFSEagle avatar Sep 10 '22 16:09 TheFGFSEagle

If I remove includeCenter=True it works.

TheFGFSEagle avatar Sep 10 '22 16:09 TheFGFSEagle

Okay, played around a bit with Overpass-Turbo and this module, and the problem is that with includeCenter=True, out body; becomes ´out center; out body;whereas it should only beout center;´ then. To bypass this issue, one can use out="center" instead.

TheFGFSEagle avatar Sep 10 '22 16:09 TheFGFSEagle

If the data is returned twice here, I would assume that it is already returned twice by Overpass. I recommend to run the query directly in Overpass and check the output. If this confirms my assumption, I advise to read their documentation.

mocnik-science avatar Sep 10 '22 16:09 mocnik-science

I did run the query directly in Overpass, and I found that for every ´out´ keyword all matches are outputted once - if there's both ´out body;andout center´, then first normal body response is returned and then the same thing again, just with additional center keys for each way - so out center; implies ´out body;, and I think the overpassQueryBuildershould account for that by only putting oneout` keyword into the query string.

TheFGFSEagle avatar Sep 10 '22 17:09 TheFGFSEagle

Oh, I see. I have to check the logics in detail. Stay tuned (might take some days).

mocnik-science avatar Sep 10 '22 17:09 mocnik-science

no problem, thanks ! :)

TheFGFSEagle avatar Sep 10 '22 17:09 TheFGFSEagle