I am using the following query to get all the airports in Manitoba that have an IATA or ICAO code associated with them (maybe not the most efficient code, so feel free to suggest something better):

[out:json][timeout:25];
area["name"="Manitoba"]->.a;

(
  node(area.a)["aeroway"="aerodrome"]["iata"];
  way(area.a)["aeroway"="aerodrome"]["iata"];
  relation(area.a)["aeroway"="aerodrome"]["iata"];

  node(area.a)["aeroway"="aerodrome"]["icao"];
  way(area.a)["aeroway"="aerodrome"]["icao"];
  relation(area.a)["aeroway"="aerodrome"]["icao"];
)->.airports;

.airports out center;

What I'd like to do now is, for each of those airports, find the nearest city (or town or whatever) to the airport. How can I do that? The end result would ideally be some JSON structure that gave me something like the following:

[
  {
    "id": 7932149,
    "center": {
      "lat": 49.9104284,
      "lon": -97.2381871
    },
    "iata": "YWG",
    "icao": "CYWG",
    "name": "Winnipeg James Armstrong Richardson International Airport",
    "nearest_city": {
      "id": "123456",
      "name": "Winnipeg",
      "center": {
        "lat": 49.9,
        "lon": -97.0,
      },
      "admin_level": 8,
      "type": "city"
    }
  },
  ... more entries ...
]

asked 06 Jun '19, 18:10

cviebrock_ppn's gravatar image

cviebrock_ppn
11112
accept rate: 0%

Did you find a solutions for this?

(12 Sep '19, 13:59) Javisst

This doesn't fully return the nearest, but should get you started:

[out:json];
area[name=Manitoba];
nwr(area)[aeroway=aerodrome][~"iata|icao"~"."]->.airports;

foreach.airports->.elem(
  nwr(around.elem:100000)[place=city];
  out geom;
);

.airports out center;

{{style: 
node [aeroway]{color:green;fill-color:green; symbol-size:5}
node [place]{color:red;fill-color:red; symbol-size:20;fill-opacity:0.5}
way [place]{color:red; opacity:0.5}
relation [place]{color:red; opacity:0.5}
}}

https://overpass-turbo.eu/s/PFZ

The third line is just a concentration of your routine. It uses regular expressions (~ means 'something like')

It then loops through each airport & finds any city with the specified distance (in metres).

T oget the nearest you'll have to perform some post processing.

PS I'm not convinced the admin ways should have place tags

permanent link

answered 12 Jan, 16:39

DaveF's gravatar image

DaveF
1.5k576784
accept rate: 7%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×381
×22
×16
×3

question asked: 06 Jun '19, 18:10

question was seen: 626 times

last updated: 12 Jan, 16:39

powered by OSQA