Overview

This package uses regularly updated open source airport data to provide convenience tools for working with airport name and location data. These tools include functions to:

  • Lookup airports by name, IATA designation, or IACO designation and translate names into designations and vice-versa
  • Lookup airports by city or coordinate location
  • Lookup airports within vicinity of a specified location
  • Calculate distances between pairs of airports

Data

Airport data is from the OpenFlights Airport Database made available under the Open Database License.

Disclaimer on the data from OpenFlights:

This data is not suitable for navigation. OpenFlights does not assume any responsibility whatsoever for its accuracy, and consequently assumes no liability whatsoever for results obtained or loss or damage incurred as a result of application of the data. OpenFlights expressly disclaims all warranties, expressed or implied, including but not limited to implied warranties of merchantability and fitness for any particular purpose.

Lookup Functions

This packages primary use-case is to facilitate working with and translating structured airport data from one format into another.

airport_lookup

The airport_lookup() function takes either an IATA code, an IACO code, or an airport name, and returns a translated value of selected output type.

airport_lookup("YVR", input_type = "IATA", output_type = "name")
#> [1] "Vancouver International Airport"
airport_lookup("Vancouver International Airport", input_type = "name", output_type ="IATA")
#> [1] "YVR"

If an input type is unknown or not provided, airport_lookup will attempt to guess the appropriate input type. Output type should always be specified; however.

airport_lookup("YVR", output_type = "city")
#> [1] "Vancouver"

airport_detail

The airport_detail function returns all available information for an airport given an airport name, IATA code, or ICAO code as input. The input type can be manually specified, but if nothing is provided function will attempt to guess the correct input type. If no matches are returned, similarly named objects will be returned as suggestions with a warning.

airport_detail("YVR")
#> # A tibble: 1 x 17
#>   `OpenFlights ID` Name  City  IATA  ICAO  Country `Country Code`
#>              <dbl> <chr> <chr> <chr> <chr> <chr>   <chr>         
#> 1              156 Vanc… Vanc… YVR   CYVR  Canada  124           
#> # … with 10 more variables: `Country Code (Alpha-2)` <chr>, `Country Code
#> #   (Alpha-3)` <chr>, Latitude <dbl>, Longitude <dbl>, Altitude <dbl>,
#> #   UTC <dbl>, DST <chr>, Timezone <chr>, Type <chr>, Source <chr>

airport_location

The airport_location function returns longitude/latitude coordinate pairs for the location of an airport, using an airport name, IATA code, or ICAO code as input argument.

airport_location("CYVR", input_type = "ICAO")
#> # A tibble: 1 x 2
#>   Latitude Longitude
#>      <dbl>     <dbl>
#> 1     49.2     -123.

city_airports

The city_airports function takes a city normal city name as an input argument and returns all airports associated with that city. Airports are typically associated with their local metropolitan area but some exceptions may be present in the data. If there are no matching results in the data for the city argument, a list of closely named alternatives will be suggested with a warning.

# Display all airports serving a given city
city_airports("Vancouver")
#> # A tibble: 5 x 17
#>   `OpenFlights ID` Name  City  IATA  ICAO  Country `Country Code`
#>              <dbl> <chr> <chr> <chr> <chr> <chr>   <chr>         
#> 1              156 Vanc… Vanc… "YVR" CYVR  Canada  124           
#> 2             4107 Coal… Vanc… "\\N" CAQ3  Canada  124           
#> 3             5500 Vanc… Vanc… "CXH" CYHC  Canada  124           
#> 4            12090 Vanc… Vanc… "\\N" CAM9  Canada  124           
#> 5            13022 Harb… Vanc… "\\N" CBC7  Canada  124           
#> # … with 10 more variables: `Country Code (Alpha-2)` <chr>, `Country Code
#> #   (Alpha-3)` <chr>, Latitude <dbl>, Longitude <dbl>, Altitude <dbl>,
#> #   UTC <dbl>, DST <chr>, Timezone <chr>, Type <chr>, Source <chr>

Distance Functions

This package also includes some convenience functions for working with distances between airports.

airport_distance

The airport_distance function takes two airport IATA codes as arguments and returns the great circle distance between the two airports. Distances are returned in kilometres. Distances are calculated using the Haversine formula which assumes a spherical earth.

airport_distance("YVR","LHR")
#> [1] 7580.963

While the Haversine formula is reasonably accurate for most uses, due to the Earth’s ellipsoidal nature, the Haversine formula may result in errors of up to 0.3% in some areas, particularly near the poles. If distance accuracy is critical, there are more robust distance measures implemented as options in the geosphere package.

airports_near_airport

Another common airport-related task is to locate airports in the vicinity of a city or specified location. This is easy to implement with the airports_near_airport() and airports_around() functions.

The airports_near_airport function takes an airport name, IATA code, or IACO code as an input argument, and returns all other airports within a 100km radius by default. Other distance ranges can be specified by modifying the default distance = 100 parameter.

airports_near_airport("YEG")
#> # A tibble: 3 x 17
#>   `OpenFlights ID` Name  City  IATA  ICAO  Country `Country Code`
#>              <dbl> <chr> <chr> <chr> <chr> <chr>   <chr>         
#> 1               49 Edmo… Edmo… YEG   CYEG  Canada  124           
#> 2              131 Rock… Rock… YRM   CYRM  Canada  124           
#> 3              165 Edmo… Edmo… YXD   CYXD  Canada  124           
#> # … with 10 more variables: `Country Code (Alpha-2)` <chr>, `Country Code
#> #   (Alpha-3)` <chr>, Latitude <dbl>, Longitude <dbl>, Altitude <dbl>,
#> #   UTC <dbl>, DST <chr>, Timezone <chr>, Type <chr>, Source <chr>

airports_around

The airports_around function takes three arguments, a latitude coordinate, a longitude coordinate and a specified distance in kilometres and lookups all airports within the specified radius around the input coordinates.

airports_around(lat = 49.2, lon = -123, distance = 20)
#> # A tibble: 5 x 17
#>   `OpenFlights ID` Name  City  IATA  ICAO  Country `Country Code`
#>              <dbl> <chr> <chr> <chr> <chr> <chr>   <chr>         
#> 1              156 Vanc… Vanc… "YVR" CYVR  Canada  124           
#> 2             5500 Vanc… Vanc… "CXH" CYHC  Canada  124           
#> 3             7273 Boun… Boun… "YDT" CZBB  Canada  124           
#> 4            12090 Vanc… Vanc… "\\N" CAM9  Canada  124           
#> 5            13022 Harb… Vanc… "\\N" CBC7  Canada  124           
#> # … with 10 more variables: `Country Code (Alpha-2)` <chr>, `Country Code
#> #   (Alpha-3)` <chr>, Latitude <dbl>, Longitude <dbl>, Altitude <dbl>,
#> #   UTC <dbl>, DST <chr>, Timezone <chr>, Type <chr>, Source <chr>

This package does not include tools for working with online geocoding or gazeteer lookups by design to keep dependencies as minimal as possible and to work without needing an internet connection. Geocoding and coordinate lookup tools are available in a number of packages including ggmap, googleway, tmap, nominatim, rmapzen, and others. In order to locate airports near a specified named location such as a city name or address, first geocode the named location and then use the resulting coordinates as an input into airports_around().