locodedb

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAirportNotFound = errors.New("airport not found")

ErrAirportNotFound is returned by AirportRecord readers when the required airport is not found.

View Source
var ErrCountryNotFound = errors.New("country not found")
View Source
var ErrSubDivNotFound = errors.New("subdivision not found")

Functions

func FillDatabase

func FillDatabase(table SourceTable, airports AirportDB, continents ContinentsDB, names NamesDB, db CsvDB) error

FillDatabase generates the location database based on the UN/LOCODE table.

func PointFromCoordinates

func PointFromCoordinates(crd *Coordinates) (locodedb.Point, error)

PointFromCoordinates converts a UN/LOCODE coordinates to a Point.

Types

type AirportDB

type AirportDB interface {
	// Must return the record by UN/LOCODE table record.
	//
	// Must return ErrAirportNotFound if there is no
	// related airport in the database.
	Get(Record) (*AirportRecord, error)
}

AirportDB is an interface of airport database.

type AirportRecord

type AirportRecord struct {
	// Name of the country where airport is located.
	CountryName string

	// Geo point where airport is located.
	Point locodedb.Point
}

AirportRecord represents the entry in airport database.

type ContinentsDB

type ContinentsDB interface {
	// Must return continent of the geo point.
	PointContinent(locodedb.Point) (*locodedb.Continent, error)
}

ContinentsDB is an interface of continent database.

type Coordinates

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

Coordinates represents the coordinates of the location from UN/LOCODE table.

func CoordinatesFromString

func CoordinatesFromString(s string) (*Coordinates, error)

CoordinatesFromString parses a string and returns the location's coordinates.

func (*Coordinates) Latitude

func (c *Coordinates) Latitude() *LatitudeCode

Latitude returns the location's latitude.

func (*Coordinates) Longitude

func (c *Coordinates) Longitude() *LongitudeCode

Longitude returns the location's longitude.

type CsvDB

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

CsvDB is a resulting database in CSV format. Path should be a valid path to the directory.

func New

func New(path string) CsvDB

func (*CsvDB) Put

func (db *CsvDB) Put(data []Data) error

Put writes the []Data to the CSV files.

type Data

type Data struct {
	Key    locodedb.Key
	Record locodedb.Record
}

Data is a struct that contains the Key and the Record.

type LatitudeCode

type LatitudeCode coordinateCode

LatitudeCode represents the value of the latitude of the location conforming to UN/LOCODE specification.

func LatitudeFromString

func LatitudeFromString(s string) (*LatitudeCode, error)

LatitudeFromString parses a string and returns the location's latitude.

func (*LatitudeCode) Degrees

func (lc *LatitudeCode) Degrees() (l [latDegDigits]uint8)

Degrees returns the latitude's degrees.

func (*LatitudeCode) Hemisphere

func (lc *LatitudeCode) Hemisphere() LatitudeHemisphere

Hemisphere returns the latitude's hemisphere code.

func (*LatitudeCode) Minutes

func (lc *LatitudeCode) Minutes() [minutesDigits]uint8

Minutes returns the latitude's minutes.

type LatitudeHemisphere

type LatitudeHemisphere [hemisphereSymbols]uint8

LatitudeHemisphere represents the hemisphere of the earth along the equator.

func (LatitudeHemisphere) North

func (h LatitudeHemisphere) North() bool

North returns true for the northern hemisphere.

type LongitudeCode

type LongitudeCode coordinateCode

LongitudeCode represents the value of the longitude of the location conforming to UN/LOCODE specification.

func LongitudeFromString

func LongitudeFromString(s string) (*LongitudeCode, error)

LongitudeFromString parses a string and returns the location's longitude.

func (*LongitudeCode) Degrees

func (lc *LongitudeCode) Degrees() (l [lngDegDigits]uint8)

Degrees returns the longitude's degrees.

func (*LongitudeCode) Hemisphere

func (lc *LongitudeCode) Hemisphere() LongitudeHemisphere

Hemisphere returns the longitude's hemisphere code.

func (*LongitudeCode) Minutes

func (lc *LongitudeCode) Minutes() [minutesDigits]uint8

Minutes returns the longitude's minutes.

type LongitudeHemisphere

type LongitudeHemisphere [hemisphereSymbols]uint8

LongitudeHemisphere represents the hemisphere of the earth // along the Greenwich meridian.

func (LongitudeHemisphere) East

func (h LongitudeHemisphere) East() bool

East returns true for the eastern hemisphere.

type NamesDB

type NamesDB interface {
	// Must resolve a country code to a country name.
	//
	// Must return ErrCountryNotFound if there is no
	// country with the provided code.
	CountryName(*locodedb.CountryCode) (string, error)

	// Must resolve (country code, subdivision code) to
	// a subdivision name.
	//
	// Must return ErrSubDivNotFound if either country or
	// subdivision is not presented in database.
	SubDivName(*locodedb.CountryCode, string) (string, error)
}

NamesDB is an interface of the location namespace.

type Record

type Record struct {
	// Combination of a 2-character country code and a 3-character location code.
	LOCODE [2]string

	// Name of the locations which has been allocated a UN/LOCODE.
	Name string

	// Names of the locations which have been allocated a UN/LOCODE without diacritic signs.
	NameWoDiacritics string

	// ISO 1-3 character alphabetic and/or numeric code for the administrative division of the country concerned.
	SubDiv string

	// 8-digit function classifier code for the location.
	Function string

	// Status of the entry by a 2-character code.
	Status string

	// Last date when the location was updated/entered.
	Date string

	// The IATA code for the location if different from location code in column LOCODE.
	IATA string

	// Geographical coordinates (latitude/longitude) of the location, if there is any.
	Coordinates string

	// Some general remarks regarding the UN/LOCODE in question.
	Remarks string
}

Record represents a single record of the UN/LOCODE table.

type SourceTable

type SourceTable interface {
	// Must iterate over all entries of the table
	// and pass next entry to the handler.
	//
	// Must return handler's errors directly.
	IterateAll(func(Record) error) error
}

SourceTable is an interface of the UN/LOCODE table.

Directories

Path Synopsis
continents

Jump to

Keyboard shortcuts

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