This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Find nearest cities to set of airports

0

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

One Answer:

1

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

answered 12 Jan '20, 16:39

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

Source code available on GitHub .