alphafoxtrot

package module
v0.0.0-...-793a4fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 13 Imported by: 0

README

go-airport-finder

This is a Golang library which retrieves all sorts of information about airports around the world. The underlying data is based on data collected and provided by OurAirports.com.

An initial version of this library was built to power the "Airport Finder" for the GoPilot.

Installation

$ go get github.com/grumpypixel/go-airport-finder

The API

This should be pretty straightforward and hopefully easy-to-use.

The following snippets are based on the provided example code.

// Create an AirportFinder instance
finder := alphafoxtrot.NewAirportFinder()

// Create LoadOptions with preset filepaths
dataDir := "./data"
options := alphafoxtrot.PresetLoadOptions(dataDir)

// Specify a filter what airport types should be loaded, in this case: all airports, please.
filter := alphafoxtrot.AirportTypeAll

// Load the airport data into memory
if err := finder.Load(options, filter); len(err) > 0 {
	log.Println("errors:", err)
}
// Alternatively, you can specify the LoadOptions "manually".
// So in this case, only airports, frequencies and runways will be loaded.
// Regions, countries, navaids will be omitted.
options := alphafoxtrot.LoadOptions{
	AirportsFilename:    "./data/airports.csv",            // *required*
	FrequenciesFilename: "./data/airport-frequencies.csv", // optional
	RunwaysFilename      "./data/runways.csv",             // optional
}

Please note that the code above assumes that the necessary .CSV files are located in a subdirectory named "data".

You can download the latest version of the .CSV files directly from OurAirports.

// A hacky way to download all needed files is by calling DownloadDatabase()
dataDir := "./data"
alphafoxtrot.DownloadDatabase(dataDir) // assuming that the given directory exists...

So much for the initialization part.

// Find an airport by its ICAO code
if airport := finder.FindAirportByICAOCode("KLAX"); airport != nil {
	fmt.Println(*airport)
}
// Find an airport by its IATA code
if airport := finder.FindAirportByIATACode("DUS"); airport != nil {
	fmt.Println(*airport)
}
// Find the nearest active airport within a given radius
latitude := 33.942501
longitude := -118.407997
radiusInMeters := alphafoxtrot.NauticalMilesToMeters(25)
airportTypeFilter := alphafoxtrot.AirportTypeActive
if airport := finder.FindNearestAirport(latitude, longitude, radiusInMeters, airportTypeFilter); airport != nil {
	fmt.Println(*airport)
}
// Find the active airports with a runway (so no heliports and no seaplane based airports) within a given radius
latitude := 33.942501
longitude := -118.407997
radiusInMeters := alphafoxtrot.MilesToMeters(61)
maxResults := 10
airportTypeFilter := alphafoxtrot.AirportTypeActive|alphafoxtrot.AirportTypeRunways
airports := finder.FindNearestAirports(latitude, longitude, radiusInMeters, maxResults, airportTypeFilter)
for i, airport := range airports {
	fmt.Println(i, *airport)
}
// Find all large airports in a specific region
regionISOCode := "US-CA"
latitude := 33.942501
longitude := -118.407997
radiusInMeters := alphafoxtrot.NauticalMilesToMeters(100)
maxResults := 10
airportTypeFilter := alphafoxtrot.AirportTypeMedium|alphafoxtrot.AirportTypeSmall
airports := finder.FindNearestAirportsByRegion(regionISOCode, latitude, longitude, radiusInMeters, maxResults, airportTypeFilter)
for i, airport := range airports {
	fmt.Println(i, *airport)
}
// Find all large and medium airports in a country
countryISOCode := "IS"
latitude := 64.1299972534
longitude := -21.9405994415
radiusInMeters := alphafoxtrot.NauticalMilesToMeters(250)
maxResults := 10
airportTypeFilter := alphafoxtrot.AirportTypeLarge|alphafoxtrot.AirportTypeMedium
airports := finder.FindNearestAirportsByCountry(countryISOCode, latitude, longitude, radiusInMeters, maxResults, airportTypeFilter)
for i, airport := range airports {
	fmt.Println(i, *airport)
}
// Find the nearest navaids within a given radius
latitude := 33.942501
longitude := -118.407997
radiusInMeters := alphafoxtrot.KilometersToMeters(50)
maxResults := 10
navaids := finder.FindNearestNavaids(latitude, longitude, radiusInMeters, maxResults)
for i, navaid := range navaids {
	fmt.Println(i, *navaid)
}
// Find the navaids associated with an airport (by ICAO code)
airportICAOCode := "CYYC"
navaids := finder.FindNavaidsByAirportICAOCode(airportICAOCode)
for i, navaid := range navaids {
	fmt.Println(i, *navaid)
}

OurAirports

Terms of use for the data

From OurAirports:

"DOWNLOAD AND USE AT YOUR OWN RISK! We hereby release all of these files into the Public Domain, with no warranty of any kind — By downloading any of these files, you agree that OurAirports.com, Megginson Technologies Ltd., and anyone involved with the web site or company hold no liability for anything that happens when you use the data, including (but not limited to) computer damage, lost revenue, flying into cliffs, or a general feeling of drowsiness that persists more than two days.

Do you agree with the above conditions? If so, then download away!"

Shoutouts

Big thanks go out to David Megginson and all contributors of OurAirports.com. What an impressive piece of collected awesomeness!

Documentation

Index

Constants

View Source
const (
	AirportTypeUnknown      uint64 = 0x00
	AirportTypeClosed       uint64 = 0x01
	AirportTypeHeliport     uint64 = 0x02
	AirportTypeSeaplaneBase uint64 = 0x04
	AirportTypeSmall        uint64 = 0x08
	AirportTypeMedium       uint64 = 0x10
	AirportTypeLarge        uint64 = 0x20
	AirportTypeAll          uint64 = AirportTypeClosed | AirportTypeHeliport | AirportTypeSeaplaneBase | AirportTypeSmall | AirportTypeMedium | AirportTypeLarge
	AirportTypeActive       uint64 = AirportTypeHeliport | AirportTypeSeaplaneBase | AirportTypeSmall | AirportTypeMedium | AirportTypeLarge
	AirportTypeRunways      uint64 = AirportTypeSmall | AirportTypeMedium | AirportTypeLarge
)
View Source
const (
	AirportsFileKey    = "airports"
	FrequenciesFileKey = "frequencies"
	RunwaysFileKey     = "runways"
	RegionsFileKey     = "regions"
	CountriesFileKey   = "countries"
	NavaidsFileKey     = "navaids"
	OurAirportsBaseURL = "https://ourairports.com/data/"
)
View Source
const (
	AirportTypeClosedName       = "closed"
	AirportTypeSmallName        = "small_airport"
	AirportTypeMediumName       = "medium_airport"
	AirportTypeLargeName        = "large_airport"
	AirportTypeHeliportName     = "heliport"
	AirportTypeSeaplaneBaseName = "seaplane_base"
	AirportTypeUnknownName      = "unknown"
)
View Source
const (
	DegToRad    float64 = math.Pi / 180.0
	EarthRadius float64 = 6371.0 * 1000.0
)

Variables

View Source
var OurAirportsFiles = map[string]string{
	AirportsFileKey:    "airports.csv",
	FrequenciesFileKey: "airport-frequencies.csv",
	RunwaysFileKey:     "runways.csv",
	RegionsFileKey:     "regions.csv",
	CountriesFileKey:   "countries.csv",
	NavaidsFileKey:     "navaids.csv",
}

Functions

func AirportTypeFromString

func AirportTypeFromString(typ string) uint64

func Clear

func Clear(af *AirportFinder)

func Distance

func Distance(fromLatitudeDeg, fromLongitudeDeg, toLatitudeDeg, toLongitudeDeg float64) float64

see https://stackoverflow.com/questions/43167417/calculate-distance-between-two-points-in-leaflet returns the distance between to coordinates in meters

func DownloadDatabase

func DownloadDatabase(targetDir string)

Download csv files from OurAirports.com

func KilometersToMeters

func KilometersToMeters(km float64) float64

func MetersToKilometers

func MetersToKilometers(m float64) float64

func MetersToMiles

func MetersToMiles(m float64) float64

func MetersToNauticalMiles

func MetersToNauticalMiles(m float64) float64

func MilesToMeters

func MilesToMeters(mi float64) float64

func MinInt

func MinInt(a, b int) int

func NauticalMilesToMeters

func NauticalMilesToMeters(nm float64) float64

func ParseBool

func ParseBool(str string) bool

func ParseFloat

func ParseFloat(str string) (float64, error)

func ParseInt

func ParseInt(str string) (int64, error)

func ParseUint

func ParseUint(str string) (uint64, error)

Types

type Airport

type Airport struct {
	ICAOCode         string
	Type             string
	Name             string
	LatitudeDeg      float64
	LongitudeDeg     float64
	ElevationFt      int64
	Continent        string
	Municipality     string
	ScheduledService bool
	GPSCode          string
	IATACode         string
	LocalCode        string
	HomeLink         string
	WikipediaLink    string
	Keywords         string
	Region           Region
	Country          Country
	Runways          []Runway
	Frequencies      []Frequency
	Navaids          []Navaid
}

func NewAirport

func NewAirport(airport *AirportData, region *RegionData, country *CountryData, frequencies []*FrequencyData, runways []*RunwayData, navaids []*NavaidData) *Airport

type AirportDB

type AirportDB struct {
	Airports []*AirportData
}

func NewAirportDB

func NewAirportDB() *AirportDB

func (*AirportDB) Clear

func (db *AirportDB) Clear()

func (*AirportDB) FindAll

func (db *AirportDB) FindAll(isoRegionFilter string, isoCountryFilter string, continentFilter string, airportTypeFilter uint64) []*AirportData

func (*AirportDB) FindByAirportType

func (db *AirportDB) FindByAirportType(airportTypeFilter uint64) []*AirportData

func (*AirportDB) FindByContinent

func (db *AirportDB) FindByContinent(continent string, airportTypeFilter uint64) []*AirportData

func (*AirportDB) FindByCountry

func (db *AirportDB) FindByCountry(isoCountry string, airportTypeFilter uint64) []*AirportData

func (*AirportDB) FindByIATACode

func (db *AirportDB) FindByIATACode(iataCode string) *AirportData

func (*AirportDB) FindByICAOCode

func (db *AirportDB) FindByICAOCode(icaoCode string) *AirportData

func (*AirportDB) FindByRegion

func (db *AirportDB) FindByRegion(isoRegion string, airportTypeFilter uint64) []*AirportData

func (*AirportDB) FindNearestAirport

func (db *AirportDB) FindNearestAirport(latitudeDeg, longitudeDeg, radius float64, airportTypeFilter uint64) *AirportData

func (*AirportDB) FindNearestAirports

func (db *AirportDB) FindNearestAirports(latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int, airportTypeFilter uint64) []*AirportData

func (*AirportDB) Parse

func (db *AirportDB) Parse(file string, airportTypeFilter uint64, skipFirstLine bool) error

type AirportData

type AirportData struct {
	ID               uint64
	ICAOCode         string
	Type             string
	TypeFlag         uint64
	Name             string
	LatitudeDeg      float64
	LongitudeDeg     float64
	ElevationFt      int64
	Continent        string
	ISOCountry       string
	ISORegion        string
	Municipality     string
	ScheduledService bool
	GPSCode          string
	IATACode         string
	LocalCode        string
	HomeLink         string
	WikipediaLink    string
	Keywords         string
}

func FindNearestAirports

func FindNearestAirports(airports []*AirportData, latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int) []*AirportData

type AirportFinder

type AirportFinder struct {
	// contains filtered or unexported fields
}

func NewAirportFinder

func NewAirportFinder() *AirportFinder

func (*AirportFinder) FindAirportByIATACode

func (af *AirportFinder) FindAirportByIATACode(iataCode string) *Airport

func (*AirportFinder) FindAirportByICAOCode

func (af *AirportFinder) FindAirportByICAOCode(icaoCode string) *Airport

func (*AirportFinder) FindAirportByType

func (af *AirportFinder) FindAirportByType(airportTypeFilter uint64) []*Airport

func (*AirportFinder) FindAllAirports

func (af *AirportFinder) FindAllAirports(isoRegionFilter, isoCountryFilter, continentFilter string, airportTypeFilter uint64) []*Airport

func (*AirportFinder) FindAllNavaids

func (af *AirportFinder) FindAllNavaids(isoCountryFilter string) []*Navaid

func (*AirportFinder) FindNavaidsByAirportICAOCode

func (af *AirportFinder) FindNavaidsByAirportICAOCode(icaoCode string) []*Navaid

func (*AirportFinder) FindNearestAirport

func (af *AirportFinder) FindNearestAirport(latitudeDeg, longitudeDeg, radiusMeters float64, airportTypeFilter uint64) *Airport

func (*AirportFinder) FindNearestAirports

func (af *AirportFinder) FindNearestAirports(latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int, airportTypeFilter uint64) []*Airport

func (*AirportFinder) FindNearestAirportsByCountry

func (af *AirportFinder) FindNearestAirportsByCountry(isoCountry string, latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int, airportTypeFilter uint64) []*Airport

func (*AirportFinder) FindNearestAirportsByRegion

func (af *AirportFinder) FindNearestAirportsByRegion(isoRegion string, latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int, airportTypeFilter uint64) []*Airport

func (*AirportFinder) FindNearestNavaids

func (af *AirportFinder) FindNearestNavaids(latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int) []*Navaid

func (*AirportFinder) Load

func (af *AirportFinder) Load(options *LoadOptions, airportFilter uint64) []error

type Country

type Country struct {
	ISOCode       string
	Name          string
	Continent     string
	WikipediaLink string
	Keywords      string
}

func NewCountry

func NewCountry(country *CountryData) *Country

type CountryDB

type CountryDB struct {
	Countries map[string]*CountryData
}

func NewCountryDB

func NewCountryDB() *CountryDB

func (*CountryDB) Clear

func (db *CountryDB) Clear()

func (*CountryDB) FindByISOCode

func (db *CountryDB) FindByISOCode(isoCode string) *CountryData

func (*CountryDB) Parse

func (db *CountryDB) Parse(file string, skipFirstLine bool) error

type CountryData

type CountryData struct {
	ID            uint64
	ISOCode       string
	Name          string
	Continent     string
	WikipediaLink string
	Keywords      string
}

type Frequency

type Frequency struct {
	Type         string
	Description  string
	FrequencyMHZ float64
}

func NewFrequency

func NewFrequency(frequency *FrequencyData) *Frequency

type FrequencyDB

type FrequencyDB struct {
	Frequencies map[uint64][]*FrequencyData
}

func NewFrequencyDB

func NewFrequencyDB() *FrequencyDB

func (*FrequencyDB) Clear

func (db *FrequencyDB) Clear()

func (*FrequencyDB) FindByAirportID

func (db *FrequencyDB) FindByAirportID(airportID uint64) []*FrequencyData

func (*FrequencyDB) Parse

func (db *FrequencyDB) Parse(file string, skipFirstLine bool) error

type FrequencyData

type FrequencyData struct {
	ID           uint64
	AirportID    uint64
	AirportIdent string
	Type         string
	Description  string
	FrequencyMHZ float64
}

type LoadOptions

type LoadOptions struct {
	AirportsFilename    string // required, usually: airports.csv
	FrequenciesFilename string // optional, usually: airport-frequencies.csv
	RunwaysFilename     string // optional, usually: runways.csv
	RegionsFilename     string // optional, usually: regions.csv
	CountriesFilename   string // optional, usually: countries.csv
	NavaidsFilename     string // optional, usually: navaids.csv
}

func PresetLoadOptions

func PresetLoadOptions(baseDir string) *LoadOptions

type MyProgress

type MyProgress struct{}

func (MyProgress) Done

func (p MyProgress) Done(sourceURL string)

func (MyProgress) Start

func (p MyProgress) Start(sourceURL string)

func (MyProgress) Update

func (p MyProgress) Update(sourceURL string, percentage float64, bytesRead, contentLength int64)
type Navaid struct {
	Ident                string
	Name                 string
	Type                 string
	FrequencyKHZ         uint64
	LatitudeDeg          float64
	LongitudeDeg         float64
	ElevationFt          int64
	ISOCountry           string
	DMEFrequencyKHZ      uint64
	DMEChannel           string
	DMELatitudeDeg       float64
	DMELongitudeDeg      float64
	DMEElevationFt       int64
	SlavedVariationDeg   float64
	MagneticVariationDeg float64
	UsageType            string
	Power                string
	AssociatedAirport    string
}

func NewNavaid

func NewNavaid(navaid *NavaidData) *Navaid
type NavaidDB struct {
	Navaids []*NavaidData
}

func NewNavaidDB

func NewNavaidDB() *NavaidDB
func (db *NavaidDB) Clear()
func (db *NavaidDB) FindByAirportICAOCode(icaoCode string) []*NavaidData
func (db *NavaidDB) FindNearestNavaids(latitudeDeg, longitudeDeg, radiusMeters float64, maxResults int) []*NavaidData
func (db *NavaidDB) Parse(file string, skipFirstLine bool) error
type NavaidData struct {
	ID                   uint64
	Filename             string
	Ident                string
	Name                 string
	Type                 string
	FrequencyKHZ         uint64
	LatitudeDeg          float64
	LongitudeDeg         float64
	ElevationFt          int64
	ISOCountry           string
	DMEFrequencyKHZ      uint64
	DMEChannel           string
	DMELatitudeDeg       float64
	DMELongitudeDeg      float64
	DMEElevationFt       int64
	SlavedVariationDeg   float64
	MagneticVariationDeg float64
	UsageType            string
	Power                string
	AssociatedAirport    string
}

type Region

type Region struct {
	ISOCode       string
	LocalCode     string
	Name          string
	WikipediaLink string
	Keywords      string
}

func NewRegion

func NewRegion(region *RegionData) *Region

type RegionDB

type RegionDB struct {
	Regions map[string]*RegionData
}

func NewRegionDB

func NewRegionDB() *RegionDB

func (*RegionDB) Clear

func (db *RegionDB) Clear()

func (*RegionDB) FindByISOCode

func (db *RegionDB) FindByISOCode(isoCode string) *RegionData

func (*RegionDB) Parse

func (db *RegionDB) Parse(file string, skipFirstLine bool) error

type RegionData

type RegionData struct {
	ID            uint64
	ISOCode       string
	LocalCode     string
	Name          string
	Continent     string
	ISOCountry    string
	WikipediaLink string
	Keywords      string
}

type Runway

type Runway struct {
	LengthFt                    int64
	WidthFt                     int64
	Surface                     string
	Lighted                     bool
	Closed                      bool
	LowEndIdent                 string
	LowEndLatitudeDeg           float64
	LowEndLongitudeDeg          float64
	LowEndElevationFt           int64
	LowEndHeadingDegT           float64
	LowEndDisplacedThresholdFt  int64
	HighEndIdent                string
	HighEndLatitudeDeg          float64
	HighEndLongitudeDeg         float64
	HighEndElevationFt          int64
	HighEndHeadingDegT          float64
	HighEndDisplacedThresholdFt int64
}

func NewRunway

func NewRunway(runway *RunwayData) *Runway

type RunwayDB

type RunwayDB struct {
	Runways map[uint64][]*RunwayData
}

func NewRunwayDB

func NewRunwayDB() *RunwayDB

func (*RunwayDB) Clear

func (db *RunwayDB) Clear()

func (*RunwayDB) FindByAirportID

func (db *RunwayDB) FindByAirportID(airportID uint64) []*RunwayData

func (*RunwayDB) Parse

func (db *RunwayDB) Parse(file string, skipFirstLine bool) error

type RunwayData

type RunwayData struct {
	ID                          uint64
	AirportID                   uint64
	AirportIdent                string
	LengthFt                    int64
	WidthFt                     int64
	Surface                     string
	Lighted                     bool
	Closed                      bool
	LowEndIdent                 string
	LowEndLatitudeDeg           float64
	LowEndLongitudeDeg          float64
	LowEndElevationFt           int64
	LowEndHeadingDegT           float64
	LowEndDisplacedThresholdFt  int64
	HighEndIdent                string
	HighEndLatitudeDeg          float64
	HighEndLongitudeDeg         float64
	HighEndElevationFt          int64
	HighEndHeadingDegT          float64
	HighEndDisplacedThresholdFt int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL