igc

package module
v0.1.1-0...-e536127 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-igc

Build Status Coverage Status GoDoc Go Report Card Maintainability Test Coverage Project Status

Go library for processing and manipulating IGC files.

Current version

v0.1.0

Note: the library status is alpha. The API is subject to change. No backwards compatibility should be assumed. Use at your own risk.

First stable release will be v1.0.0.

Usage

package main

import (
	"fmt"

	"github.com/igcfs/go-igc"
)

func main() {
    s := "http://skypolaris.org/wp-content/uploads/IGS%20Files/Madrid%20to%20Jerez.igc"
    track, err := igc.ParseLocation(s)
    if err != nil {
        fmt.Errorf("Problem reading the track", err)
    }

    fmt.Printf("Pilot: %s, gliderType: %s, date: %s", 
        track.Pilot, track.GliderType, track.Date.String())
}

Resources

Testing

Tests rely on the golden files. To update the golden files, run the tests with the -update flag:

go test -update .

Documentation

$ godoc github.com/igcfs/go-igc

Acknowledgements

This is a fork from original project by Ricardo Rocha https://github.com/ezgliding/goigc

Contributing

Any form of contribution is more than welcome. Please create pull requests, contribute to the Wiki pages, or gives us heads up about ongoing projects that make use of this library. Any suggestions or feedback through email or issue tracker.

Documentation

Overview

Package igc provides means to parse and analyse files in the IGC format.

This format is defined by the International Gliding Commission (IGC) and was created to set a standard for recording gliding flights.

The full specification is available in Appendix A of the IGC FR Specification: http://www.fai.org/component/phocadownload/category/?download=11005

Calculation of the optimal flight distance considering multiple turnpoints and FAI triangles are available via Optimizers. Available Optimizers include brute force, montecarlo method, genetic algorithms, etc.

Example (Optimize)

Calculate the optimal track distance for the multiple possible tasks using the Brute Force Optimizer:

track, _ := ParseLocation("sample-flight.igc")

// In this case we use a brute force optimizer
o := NewBruteForceOptimizer(false)
r, _ := o.Optimize(track, 1, Distance)
fmt.Printf("Optimization result was: %v", r)
Output:

Example (Parse)

Parse and ParseLocation return a Track object.

// We can parse passing a file location
track, _ := ParseLocation("sample-flight.igc")

// Or similarly giving directly the contents
contents := `
AFLA001Some Additional Data
HFDTE010203
HFFXA500
HFPLTPilotincharge:EZ PILOT
	`
track, _ = Parse(contents)

// Accessing track metadata
fmt.Printf("Track Pilot: %v", track.Pilot)
fmt.Printf("Track Points %v", len(track.Pilot))
Output:

Example (Parsecontent)

Parse directly flight contents and get a Track object.

// We could pass here a string with the full contents in IGC format
track, _ := Parse(`
AFLA001Some Additional Data
HFDTE010203
HFFXA500
HFPLTPilotincharge:EZ PILOT
	`)

fmt.Printf("Track Pilot: %v", track.Pilot)
fmt.Printf("Track Points %v", len(track.Pilot))
Output:

Example (Parselocation)

Parse a given file and get a Track object.

track, _ := ParseLocation("sample-flight.igc")

fmt.Printf("Track Pilot: %v", track.Pilot)
fmt.Printf("Track Points %v", len(track.Pilot))
Output:

Example (Totaldistance)

Calculate the total track distance using the Points.

This is not a very useful metric (you should look at one of the Optimizers) instead, but it is a good example of how to use the Point data in the Track.

track, _ := ParseLocation("sample-flight.igc")
totalDistance := 0.0
for i := 0; i < len(track.Points)-1; i++ {
	totalDistance += track.Points[i].Distance(track.Points[i+1])
}
fmt.Printf("Distance was %v", totalDistance)
Output:

Index

Examples

Constants

View Source
const (
	// TimeFormat is the golang time.Parse format for IGC time.
	TimeFormat = "150405"
	// DateFormat is the golang time.Parse format for IGC time.
	DateFormat = "020106"
)
View Source
const (
	// EarthRadius is the average earth radius.
	EarthRadius = 6371.0
)

Variables

View Source
var Manufacturers = map[string]Manufacturer{
	"GCS": {'A', "GCS", "Garrecht"},
	"LGS": {'B', "LGS", "Logstream"},
	"CAM": {'C', "CAM", "Cambridge Aero Instruments"},
	"DSX": {'D', "DSX", "Data Swan/DSX"},
	"EWA": {'E', "EWA", "EW Avionics"},
	"FIL": {'F', "FIL", "Filser"},
	"FLA": {'G', "FLA", "Flarm (Track Alarm)"},
	"SCH": {'H', "SCH", "Scheffel"},
	"ACT": {'I', "ACT", "Aircotec"},
	"CNI": {'K', "CNI", "ClearNav Instruments"},
	"NKL": {'K', "NKL", "NKL"},
	"LXN": {'L', "LXN", "LX Navigation"},
	"IMI": {'M', "IMI", "IMI Gliding Equipment"},
	"NTE": {'N', "NTE", "New Technologies s.r.l."},
	"NAV": {'O', "NAV", "Naviter"},
	"PES": {'P', "PES", "Peschges"},
	"PRT": {'R', "PRT", "Print Technik"},
	"SDI": {'S', "SDI", "Streamline Data Instruments"},
	"TRI": {'T', "TRI", "Triadis Engineering GmbH"},
	"LXV": {'V', "LXV", "LXNAV d.o.o."},
	"WES": {'W', "WES", "Westerboer"},
	"XYY": {'X', "XYY", "Other manufacturer"},
	"ZAN": {'Z', "ZAN", "Zander"},
}

Manufacturers holds the list of available manufacturers.

This list is defined in the IGC specification, section A2.5.6.

Functions

func DecimalFromDMD

func DecimalFromDMD(dmd string) float64

DecimalFromDMD returns the decimal representation (in radians) of the given DMD.

DMD is a representation of a coordinate in Decimal,Minutes,100thMinute with an extra character indicating north, south, east, west.

Examples: N512688, W0064364, S342212, E0021275

func DecimalFromDMS

func DecimalFromDMS(dms string) float64

DecimalFromDMS returns the decimal representation (in radians) of the given DMS.

DMS is a representation of a coordinate in Decimal,Minutes,Seconds, with an extra character indicating north, south, east, west.

Examples: N512646, W0064312, S342244, E0021233

func Distance

func Distance(task Task) float64

Distance returns the sum of distances between each of the points in the Task.

The sum is made calculating the distances between each two consecutive Points.

Types

type Event

type Event struct {
	Time time.Time
	Type string
	Data string
}

Event holds data records triggered at a given time.

This is the E record in the IGC specification, section A4.2. The events can be pilot initiated (with a PEV code), proximity alerts, etc.

type Header struct {
	Manufacturer     string
	UniqueID         string
	AdditionalData   string
	Date             time.Time
	FixAccuracy      int64
	Pilot            string
	Crew             string
	GliderType       string
	GliderID         string
	GPSDatum         string
	FirmwareVersion  string
	HardwareVersion  string
	FlightRecorder   string
	GPS              string
	PressureSensor   string
	CompetitionID    string
	CompetitionClass string
	Timezone         int
}

Header holds the meta information of a track.

This is the H record in the IGC specification, section A3.2.

type K

type K struct {
	Time   time.Time
	Fields map[string]string
}

K holds flight data needed less often than Points.

This is the K record in the IGC specification, section A4.4. Fields is a map between a given content type and its value, with the possible content types being defined in the J record.

Examples of content types include heading true (HDT) or magnetic (HDM), airspeed (IAS), etc.

type LogEntry

type LogEntry struct {
	Type string
	Text string
}

LogEntry holds a logbook/comment entry, in free format.

This is the L record in the IGC specification, section A4.5.

type Manufacturer

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

Manufacturer holds manufacturer name, short ID and char identifier.

The list of manufacturers is defined in the IGC specification, section A2.5.6. A map Manufacturers is available in this library.

type Optimizer

type Optimizer interface {
	Optimize(track Track, nPoints int, score Score) (Task, error)
}

Optimizer returns an optimal Task for the given turnpoints and Score function.

Available score functions include MaxDistance and MaxPoints, but it is possible to pass the Optimizer a custom function.

Optimizers might not support a high number of turnpoints. As an example, the BruteForceOptimizer does not perform well with nPoints > 2, and might decide to return an error instead of attempting to finalize the optimization indefinitely.

func NewBruteForceOptimizer

func NewBruteForceOptimizer(cache bool) Optimizer

NewBruteForceOptimizer returns a BruteForceOptimizer with the given characteristics.

type Point

type Point struct {
	s2.LatLng
	Time             time.Time
	FixValidity      byte
	PressureAltitude int64
	GNSSAltitude     int64
	IData            map[string]string
	NumSatellites    int
	Description      string
}

Point represents a GPS recording (single point in the track).

It is based on a golang-geo s2 LatLng, adding extra metadata such as the Time the point was recorded, pressure and GNSS altitude, number of satellites available and extra metadata added by the recorder.

You can use all methods available for a s2.LatLng on this struct.

func NewPoint

func NewPoint() Point

NewPoint returns a new Point set to latitude and longitude 0.

func NewPointFromDMD

func NewPointFromDMD(lat string, lng string) Point

NewPointFromDMD returns a Point corresponding to the given string in DMD format.

DecimalFromDMD includes more information regarding this format.

func NewPointFromDMS

func NewPointFromDMS(lat string, lng string) Point

NewPointFromDMS returns a Point corresponding to the given string in DMS format.

DecimalFromDMS includes more information regarding this format.

func NewPointFromLatLng

func NewPointFromLatLng(lat float64, lng float64) Point

NewPointFromLatLng returns a new Point with the given latitude and longitude.

func (*Point) Distance

func (p *Point) Distance(b Point) float64

Distance returns the great circle distance in kms to the given point.

Internally it uses the golang-geo s2 LatLng.Distance() method, but converts its result (an angle) to kms considering the constance EarthRadius.

type Satellite

type Satellite struct {
	Time time.Time
	Ids  []string
}

Satellite holds the IDs of the available satellites at a given Time.

This is the F record in the IGC specification, section A4.3.

type Score

type Score func(task Task) float64

Score functions calculate a score for the given Task.

The main use of these functions is in passing them to the Optimizers, so they can evaluate each Task towards different goals.

Example functions include the total distance between all turn points or an online competition (netcoupe, online contest) score which takes additional metrics of each leg into account.

type Task

type Task struct {
	DeclarationDate time.Time
	Date            time.Time
	Number          int
	Takeoff         Point
	Start           Point
	Turnpoints      []Point
	Finish          Point
	Landing         Point
	Description     string
}

Task holds all the metadata put in a pre-declared task to be performed.

This is the C record in the IGC specification, section A3.5.

func (*Task) Distance

func (task *Task) Distance() float64

Distance returns the total distance in kms between the turn points.

It includes the Start and Finish fields as the first and last point, respectively, with the Turnpoints in the middle. The return value is sum of all distances between each consecutive point.

type Track

type Track struct {
	Header
	Points        []Point
	K             []K
	Events        []Event
	Satellites    []Satellite
	Logbook       []LogEntry
	Task          Task
	DGPSStationID string
	Signature     string
}

Track holds all IGC flight data (header and GPS points).

func NewTrack

func NewTrack() Track

NewTrack returns a new instance of Track, with fields initialized to zero.

func Parse

func Parse(content string) (Track, error)

Parse returns a Track object corresponding to the given content.

The value of content should be a text string with all the flight data in the IGC format.

func ParseLocation

func ParseLocation(location string) (Track, error)

ParseLocation returns a Track object corresponding to the given file.

It calls Parse internally, so the file content should be in IGC format.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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