mocnik-science / osm-python-tools

A library to access OpenStreetMap related services
GNU General Public License v3.0
440 stars 48 forks source link

Overpass returns every way twice #66

Open TheFGFSEagle opened 2 years ago

TheFGFSEagle commented 2 years ago

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%3B%0A%2F%2F%20print%20results%0Aout%20body%3B%0A%3E%3B%0Aout%20skel%20qt%3B&C=-6.02452;144.97202;15).

TheFGFSEagle commented 2 years ago

If I remove includeCenter=True it works.

TheFGFSEagle commented 2 years ago

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.

mocnik-science commented 2 years ago

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.

TheFGFSEagle commented 2 years ago

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 theoverpassQueryBuildershould account for that by only putting oneout` keyword into the query string.

mocnik-science commented 2 years ago

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

TheFGFSEagle commented 2 years ago

no problem, thanks ! :)