gpx

package module
v0.0.0-...-f95a7bb Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2016 License: MIT Imports: 7 Imported by: 1

README

gpx

Travis CI status

gpx is a Go library for parsing GPX 1.1 documents.

It supports parsing the following extensions:

  • Garmin’s TrackPoint extension (http://www.garmin.com/xmlschemas/TrackPointExtension/v1)

Installation

go get github.com/thcyron/gpx

Usage

f, err := os.Open("test.gpx")
if err != nil {
        panic(err)
}

doc, err := gpx.NewDecoder(f).Decode()
if err != nil {
        panic(err)
}

fmt.Printf("document has %d track(s)\n", len(doc.Tracks))

Documentation

Documentation is available at GoDoc.

License

gpx is licensed under the MIT license.

Documentation

Index

Constants

View Source
const GarminTrackPointExtensionNS = "http://www.garmin.com/xmlschemas/TrackPointExtension/v1"

Variables

View Source
var (
	ErrBadRootTag = errors.New("gpx: root element must be <gpx>")
	ErrGPX11Only  = errors.New("gpx: can only parse GPX 1.1 documents")
)
View Source
var (
	ErrNoSuchExtension = errors.New("gpx: no such extension")
)

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	MinLatitude  float64
	MinLongitude float64
	MaxLatitude  float64
	MaxLongitude float64
}

Bounds provides information about the document bounds.

type Copyright struct {
	Author  string
	Year    int
	License string
}

Copyright provides information about the copyright holder and license.

type Decoder

type Decoder struct {
	Strict bool
	// contains filtered or unexported fields
}

Decoder decodes a GPX document from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new decoder reading from r. The decoder operates in strict mode.

func (*Decoder) Decode

func (d *Decoder) Decode() (doc Document, err error)

Decode decodes a document.

type Document

type Document struct {
	Version  string
	Metadata Metadata
	Tracks   []Track
}

Document represents a GPX document.

func (Document) Distance

func (d Document) Distance() float64

Distance returns the document’s total distance in meters.

func (Document) Duration

func (d Document) Duration() time.Duration

Duration returns the document’s total duration.

func (Document) End

func (d Document) End() time.Time

End returns the end time of the last track.

func (Document) Start

func (d Document) Start() time.Time

Start returns the start time of the first track.

type Email

type Email struct {
	ID     string
	Domain string
}

Email represents an email address.

type GarminTrackPointExtension

type GarminTrackPointExtension struct {
	AirTemp   float64 // Air temperature (Celsius)
	WaterTemp float64 // Water temperature (Celsius)
	Depth     float64 // Diving depth (meters)
	HeartRate uint    // Heart rate (beats per minute)
	Cadence   uint    // Cadence (revs per minute)
}

GarminTrackPointExtension is Garmin’s TrackPoint extension defined by https://www8.garmin.com/xmlschemas/TrackPointExtensionv1.xsd

func ParseGarminTrackPointExtension

func ParseGarminTrackPointExtension(tokens []xml.Token) (e GarminTrackPointExtension, err error)

ParseGarminTrackPointExtension tries to parse Garmin’s TrackPoint extension from a point’s extensions tokens.

type Link struct {
	Href string
	Text string
	Type string
}

Link represents a link.

type Metadata

type Metadata struct {
	Name        string
	Description string
	Author      Person
	Copyright   Copyright
	Link        Link
	Time        time.Time
	Keywords    string
	Bounds      Bounds
	Extensions  []xml.Token
}

Metadata provides additional information about a GPX document.

type Person

type Person struct {
	Name  string
	Email Email
	Link  Link
}

Person represents a person.

type Point

type Point struct {
	Latitude   float64
	Longitude  float64
	Elevation  float64
	Time       time.Time
	Extensions []xml.Token
}

Point represents a track point. Extensions contains the raw XML tokens of the point’s extensions if it has any (excluding the <extensions> start and end tag).

func (Point) DistanceTo

func (p Point) DistanceTo(p2 Point) float64

DistanceTo returns the distance in meters to point p2.

type Segment

type Segment struct {
	Points []Point
}

Segments represents a track segment.

func (Segment) Distance

func (s Segment) Distance() float64

Distance returns the segment’s total distance in meters.

func (Segment) Duration

func (s Segment) Duration() time.Duration

Duration returns the segment’s total duration.

func (Segment) End

func (s Segment) End() time.Time

End returns the time of the last point.

func (Segment) Start

func (s Segment) Start() time.Time

Start returns the time of the first point.

type Track

type Track struct {
	Name     string
	Segments []Segment
}

Track represents a track.

func (Track) Distance

func (t Track) Distance() float64

Distance returns the track’s total distance in meters.

func (Track) Duration

func (t Track) Duration() time.Duration

Duration returns the track’s total duration.

func (Track) End

func (t Track) End() time.Time

End returns the end time of the last segment.

func (Track) Start

func (t Track) Start() time.Time

Start returns the start time of the first segment.

Jump to

Keyboard shortcuts

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