1

I am using overpy to collect data information about taxiways, taxilanes and parking positions of an airport (icao code LOWW). I was able to achieve my goal I wrote the following lines of code:

import overpy
api = overpy.Overpass()
r = api.query("""
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“taxiway in airport ”
*/
[out:xml]/*fixed by auto repair*/[timeout:25];
// fetch area “airport” to search in
area[icao~"LOWW"]->.searchArea;
// gather results
(
  // query part for: “aerodrome”
  node["aeroway"="aerodrome"](area.searchArea);
  way["aeroway"="aerodrome"](area.searchArea);
  relation["aeroway"="aerodrome"](area.searchArea);

  // query part for: “taxiway”
  node["aeroway"="taxiway"](area.searchArea);
  way["aeroway"="taxiway"](area.searchArea);
  relation["aeroway"="taxiway"](area.searchArea);

  // query part for: “taxilane”
  node["aeroway"="taxilane"](area.searchArea);
  way["aeroway"="taxilane"](area.searchArea);
  relation["aeroway"="taxilane"](area.searchArea);

  // query part for: “parking_position”
  node["aeroway"="parking_position"](area.searchArea);
  way["aeroway"="parking_position"](area.searchArea);
  relation["aeroway"="parking_position"](area.searchArea);

);
// print results
out meta;/*fixed by auto repair*/
>;
out meta qt;/*fixed by auto repair*/
""")

However my goal is to save the response into the .osm file format. Unfortunately i cannot find in the overpy documentation a way to do it. Would you be able to suggest a way to achieve my goal?

NOTE: I was thinking to use other packages as well such as osmnx but i cannot get the query as right as with overpy.

import osmnx as ox
G = ox.graph_from_place('wien flughafen austria', infrastructure='way["aeroway"]',simplify=False, custom_filter = ('["aeroway"~"taxiway|taxilane|parking_position"]'))
ox.save_load.save_as_osm(G, filename='filename.osm')
1

You don't really need the overpy package to retrieve raw OSM from overpass API.

You can do direct http calls like in the following, using requests library. We also provide the solution to both write the XML and continue parsing the result with overpy like if you would have made it without requests

You need to change following useragent variable to 'Your website or application name/your contact' like illustrated here https://github.com/riccardoklinger/OSMquery/issues/34#issuecomment-423730819 to comply to ToU

import overpy
import requests

useragent = 'Your website or application name/your contact'
headers = {
    'Connection': 'keep-alive',
    'sec-ch-ua': '"Google Chrome 80"',
    'Accept': '*/*',
    'Sec-Fetch-Dest': 'empty',
    'User-Agent': useragent,
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Origin': 'https://overpass-turbo.eu',
    'Sec-Fetch-Site': 'cross-site',
    'Sec-Fetch-Mode': 'cors',
    'Referer': 'https://overpass-turbo.eu/',
    'Accept-Language': '',
    'dnt': '1',
}

query = """
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“taxiway in airport ”
*/
[out:xml]/*fixed by auto repair*/[timeout:25];
// fetch area “airport” to search in
area[icao~"LOWW"]->.searchArea;
// gather results
(
  // query part for: “aerodrome”
  node["aeroway"="aerodrome"](area.searchArea);
  way["aeroway"="aerodrome"](area.searchArea);
  relation["aeroway"="aerodrome"](area.searchArea);

  // query part for: “taxiway”
  node["aeroway"="taxiway"](area.searchArea);
  way["aeroway"="taxiway"](area.searchArea);
  relation["aeroway"="taxiway"](area.searchArea);

  // query part for: “taxilane”
  node["aeroway"="taxilane"](area.searchArea);
  way["aeroway"="taxilane"](area.searchArea);
  relation["aeroway"="taxilane"](area.searchArea);

  // query part for: “parking_position”
  node["aeroway"="parking_position"](area.searchArea);
  way["aeroway"="parking_position"](area.searchArea);
  relation["aeroway"="parking_position"](area.searchArea);

);
// print results
out meta;/*fixed by auto repair*/
>;
out meta qt;/*fixed by auto repair*/
"""

data = {
  'data': query
}

response = requests.post('https://overpass-api.de/api/interpreter', headers=headers, data=data)

with open('/tmp/myquery.osm', 'w') as f:
    f.write(response.text)

api = overpy.Overpass()

results = api.parse_xml(response.text)


3
  • Thanks a lot for the answer that is exaclty was I was looking for. Do you perhaps know a way to make such request directly to openstreatmap? – Federico Gentile Mar 6 '20 at 7:41
  • Please don't use a fake User-Agent identifier in your own Python scripts, as it violates the ToU. Change it to your project name + contact details. – mmd Mar 6 '20 at 9:19
  • 1
    @mmd Made an edit to mention your comment (abusive use of copy to CURL in my browser debugger network panel, sorry). Better? – ThomasG77 Mar 6 '20 at 15:07

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.