gpx

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

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

Go to latest
Published: Dec 16, 2015 License: MIT Imports: 9 Imported by: 9

README

go-gpx - GPX file parser for Go

This is a simple GPX file parser for the Go language inspired by the python library gpxpy.

Documentation

Overview

Package gpx implements a simple GPX parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElevationAngle

func ElevationAngle(loc1, loc2 *Wpt, radians bool) float64

ElevationAngle calculates the elavation angle

Types

type Bounds

type Bounds struct {
	XMLName xml.Name `xml:"bounds"`
	MinLat  float64  `xml:"minlat,attr"`
	MaxLat  float64  `xml:"maxlat,attr"`
	MinLon  float64  `xml:"minlon,attr"`
	MaxLon  float64  `xml:"maxlon,attr"`
}

Bounds is a GPX bounds tag

func (*Bounds) String

func (b *Bounds) String() string
type Copyright struct {
	XMLName xml.Name `xml:"copyright"`
	Author  string   `xml:"author,attr"`
	Year    string   `xml:"year,omitempty"`
	License string   `xml:"license,omitempty"`
}

Copyright is a GPX copyright tag

type Email

type Email struct {
	XMLName xml.Name `xml:"email"`
	ID      string   `xml:"id,attr,omitempty"`
	Domain  string   `xml:"domain,attr,omitempty"`
}

Email is a GPX email tag

type Gpx

type Gpx struct {
	XMLName      xml.Name  `xml:"gpx"`
	XMLNs        string    `xml:"xmlns,attr"`
	XMLNsXsi     string    `xml:"xmlns:xsi,attr,omitempty"`
	XMLSchemaLoc string    `xml:"xsi:schemaLocation,attr,omitempty"`
	Version      string    `xml:"version,attr"`
	Creator      string    `xml:"creator,attr"`
	Metadata     *Metadata `xml:"metadata,omitempty"`
	Waypoints    Waypoints `xml:"wpt,omitempty"`
	Routes       []Rte     `xml:"rte,omitempty"`
	Tracks       []Trk     `xml:"trk"`
}

Gpx represents the root of a GPX file

func NewGpx

func NewGpx() *Gpx

NewGpx creates and returns a new Gpx objects.

func Parse

func Parse(r io.Reader) (*Gpx, error)

Parse parses a GPX reader and return a Gpx object.

func ParseFile

func ParseFile(filepath string) (*Gpx, error)

ParseFile reads a GPX file and parses it.

func (*Gpx) Bounds

func (g *Gpx) Bounds() *Bounds

Bounds returns the bounds of all tracks in a Gpx.

func (*Gpx) Clone

func (g *Gpx) Clone() *Gpx

Clone duplicates a Gpx object with deep copy.

func (*Gpx) Duration

func (g *Gpx) Duration() float64

Duration returns the duration of all tracks in a Gpx in seconds.

func (*Gpx) Length2D

func (g *Gpx) Length2D() float64

Length2D returns the 2D length of all tracks in a Gpx.

func (*Gpx) Length3D

func (g *Gpx) Length3D() float64

Length3D returns the 3D length of all tracks,

func (*Gpx) LocationAt

func (g *Gpx) LocationAt(t time.Time) []Wpt

LocationAt returns a slice of Wpts for a certain time.

func (*Gpx) MovingData

func (g *Gpx) MovingData() *MovingData

MovingData returns the moving data for all tracks in a Gpx.

func (*Gpx) Split

func (g *Gpx) Split(trackNo, segNo, pointNo int)

Split splits the Gpx segment segNo in a given track trackNo at pointNo.

func (*Gpx) TimeBounds

func (g *Gpx) TimeBounds() (start, end time.Time)

TimeBounds returns the time bounds of all tacks in a Gpx.

func (*Gpx) ToXML

func (g *Gpx) ToXML() []byte

ToXML returns the marshalled Gpx object.

func (*Gpx) UphillDownhill

func (g *Gpx) UphillDownhill() (uphill, downhill float64)

UphillDownhill returns uphill and downhill values for all tracks in a Gpx.

type Link struct {
	XMLName xml.Name `xml:"link"`
	URL     string   `xml:"href,attr,omitempty"`
	Text    string   `xml:"text,omitempty"`
	Type    string   `xml:"type,omitempty"`
}

Link is a GPX link

type Metadata

type Metadata struct {
	XMLName   xml.Name   `xml:"metadata"`
	Name      string     `xml:"name,omitempty"`
	Desc      string     `xml:"desc,omitempty"`
	Author    *Person    `xml:"author,omitempty"`
	Copyright *Copyright `xml:"copyright,omitempty"`
	Links     []Link     `xml:"link,omitempty"`
	Timestamp string     `xml:"time,omitempty"`
	Keywords  string     `xml:"keywords,omitempty"`
	Bounds    *Bounds    `xml:"bounds"`
}

Metadata is a GPX metadata tag

type MovingData

type MovingData struct {
	MovingTime      float64
	StoppedTime     float64
	MovingDistance  float64
	StoppedDistance float64
	MaxSpeed        float64
}

MovingData represents moving data

type Person

type Person struct {
	XMLName xml.Name `xml:"author"`
	Name    string   `xml:"name,omitempty"`
	Email   *Email   `xml:"email,omitempty"`
	Link    *Link    `xml:"link,omitempty"`
}

Person is a GPX person tag

type Rte

type Rte struct {
	XMLName   xml.Name `xml:"rte"`
	Name      string   `xml:"name,omitempty"`
	Cmt       string   `xml:"cmt,omitempty"`
	Desc      string   `xml:"desc,omitempty"`
	Src       string   `xml:"src,omitempty"`
	Links     []Link   `xml:"link"`
	Number    int      `xml:"number,omitempty"`
	Type      string   `xml:"type,omitempty"`
	Waypoints `xml:"rtept"`
}

Rte is a GPX Route

type Trk

type Trk struct {
	XMLName  xml.Name `xml:"trk"`
	Name     string   `xml:"name,omitempty"`
	Cmt      string   `xml:"cmt,omitempty"`
	Desc     string   `xml:"desc,omitempty"`
	Src      string   `xml:"src,omitempty"`
	Links    []Link   `xml:"link"`
	Number   int      `xml:"number,omitempty"`
	Type     string   `xml:"type,omitempty"`
	Segments []Trkseg `xml:"trkseg"`
}

Trk is a GPX track

func (*Trk) Bounds

func (trk *Trk) Bounds() *Bounds

Bounds returns the bounds of a GPX track.

func (*Trk) Duration

func (trk *Trk) Duration() float64

Duration returns the duration of a GPX track.

func (*Trk) Join

func (trk *Trk) Join(segNo, segNo2 int)

Join joins two GPX segments in a GPX track.

func (*Trk) JoinNext

func (trk *Trk) JoinNext(segNo int)

JoinNext joins a GPX segment with the next segment in the current GPX track.

func (*Trk) Length2D

func (trk *Trk) Length2D() float64

Length2D returns the 2D length of a GPX track.

func (*Trk) Length3D

func (trk *Trk) Length3D() float64

Length3D returns the 3D length of a GPX track.

func (*Trk) LocationAt

func (trk *Trk) LocationAt(t time.Time) []Wpt

LocationAt returns a slice of Wpt for a given time.

func (*Trk) MovingData

func (trk *Trk) MovingData() *MovingData

MovingData returns the moving data of a GPX track.

func (*Trk) Split

func (trk *Trk) Split(segNo, ptNo int)

Split splits a GPX segment at a point number ptNo in a GPX track.

func (*Trk) TimeBounds

func (trk *Trk) TimeBounds() (start, end time.Time)

TimeBounds returns the time bounds of a GPX track.

func (*Trk) UphillDownhill

func (trk *Trk) UphillDownhill() (uphill, downhill float64)

UphillDownhill return the uphill and downhill values of a GPX track.

type Trkseg

type Trkseg struct {
	XMLName   xml.Name `xml:"trkseg"`
	Waypoints `xml:"trkpt"`
}

Trkseg is a GPX track segment

func (*Trkseg) Join

func (seg *Trkseg) Join(seg2 *Trkseg)

Join concatenates to GPX segments.

func (*Trkseg) Split

func (seg *Trkseg) Split(i int) (*Trkseg, *Trkseg)

Split splits a GPX segment at point index i. Point i remains in first part.

type Waypoints

type Waypoints []Wpt

Waypoints is a collection of waypoints whether in a track, a route, or standalone.

func (Waypoints) Bounds

func (w Waypoints) Bounds() *Bounds

Bounds returns the bounds of a GPX segment.

func (Waypoints) Center

func (w Waypoints) Center() (lat, lon float64)

Center returns the center of a GPX route.

func (Waypoints) Duration

func (w Waypoints) Duration() float64

Duration returns the duration in seconds in a GPX segment.

func (Waypoints) Elevations

func (w Waypoints) Elevations() []float64

Elevations returns a slice with the elevations in a GPX segment.

func (Waypoints) Length2D

func (w Waypoints) Length2D() float64

Length2D returns the 2D length of a GPX segment.

func (Waypoints) Length3D

func (w Waypoints) Length3D() float64

Length3D returns the 3D length of a GPX segment.

func (Waypoints) LocationAt

func (w Waypoints) LocationAt(t time.Time) int

LocationAt returns the Wpt at a given time.

func (Waypoints) MovingData

func (w Waypoints) MovingData() *MovingData

MovingData returns the moving data of a GPX segment.

func (Waypoints) Speed

func (w Waypoints) Speed(pointIdx int) float64

Speed returns the speed at point number in a GPX segment.

func (Waypoints) TimeBounds

func (w Waypoints) TimeBounds() (start, end time.Time)

TimeBounds returns the time bounds of a GPX segment.

func (Waypoints) UphillDownhill

func (w Waypoints) UphillDownhill() (uphill, downhill float64)

UphillDownhill returns uphill and dowhill in a GPX segment.

type Wpt

type Wpt struct {
	Lat float64 `xml:"lat,attr"`
	Lon float64 `xml:"lon,attr"`
	// Position info
	Ele         float64 `xml:"ele,omitempty"`
	Timestamp   string  `xml:"time,omitempty"`
	MagVar      string  `xml:"magvar,omitempty"`
	GeoIDHeight string  `xml:"geoidheight,omitempty"`
	// Description info
	Name  string `xml:"name,omitempty"`
	Cmt   string `xml:"cmt,omitempty"`
	Desc  string `xml:"desc,omitempty"`
	Src   string `xml:"src,omitempty"`
	Links []Link `xml:"link"`
	Sym   string `xml:"sym,omitempty"`
	Type  string `xml:"type,omitempty"`
	// Accuracy info
	Fix          string  `xml:"fix,omitempty"`
	Sat          int     `xml:"sat,omitempty"`
	Hdop         float64 `xml:"hdop,omitempty"`
	Vdop         float64 `xml:"vdop,omitempty"`
	Pdop         float64 `xml:"pdop,omitempty"`
	AgeOfGpsData float64 `xml:"ageofgpsdata,omitempty"`
	DGpsID       int     `xml:"dgpsid,omitempty"`
}

Wpt is a GPX waypoint

func (*Wpt) Distance2D

func (pt *Wpt) Distance2D(pt2 *Wpt) float64

Distance2D returns the 2D distance of two GpxWpts.

func (*Wpt) Distance3D

func (pt *Wpt) Distance3D(pt2 *Wpt) float64

Distance3D returns the 3D distance of two GpxWpts.

func (*Wpt) MaxDilutionOfPrecision

func (pt *Wpt) MaxDilutionOfPrecision() float64

MaxDilutionOfPrecision returns the dilution precision of a GpxWpt.

func (*Wpt) SpeedBetween

func (pt *Wpt) SpeedBetween(pt2 *Wpt, threeD bool) float64

SpeedBetween calculates the speed between two GpxWpts.

func (*Wpt) Time

func (pt *Wpt) Time() time.Time

Time returns a timestamp string as Time object.

func (*Wpt) TimeDiff

func (pt *Wpt) TimeDiff(pt2 *Wpt) float64

TimeDiff returns the time difference of two GpxWpts in seconds.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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