gpx

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

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

Go to latest
Published: Oct 24, 2015 License: BSD-3-Clause Imports: 7 Imported by: 1

README

Go library to parse gpx files

So far it only maps gpx file to a struct (as defined in http://www.topografix.com/GPX/1/1) and is able to count track total distance.

Usage:

import "github.com/rndz/gpx"

func main() {
    g, err := gpx.ParseFile("file.gpx")
	if err != nil {
		panic(err)
	}
    // Print track distance(km).
	fmt.Println(g.Distance())

    // Use track point information
	for _, track := range g.Trk {
		for _, segment := range track.Trkseg {
			for _, pt := range segment.Trkpt {
                // Do something with pt.Lat, pt.Lon, etc...
			}
		}
	}
}

Documentation

Overview

gpx is a package to parse .gpx file as defined in http://www.topografix.com/GPX/1/1

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

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

Bounds is two lat/lon pairs defining the extent of an element.

type Copyright struct {
	Author  string `xml:"author,attr"`
	Year    string `xml:"year"`
	License string `xml:"license"`
}

Copyright represents information about copyright holder and license.

type Email

type Email struct {
	ID     string `xml:"id,attr"`
	Domain string `xml:"domain,attr"`
}

Email represents email address

type Gpx

type Gpx struct {
	XMLName  xml.Name  `xml:"gpx"`
	Version  string    `xml:"version,attr"`
	Creator  string    `xml:"creator,attr"`
	Metadata *Metadata `xml:"metadata"`
	Wpt      []*Wpt    `xml:"wpt"`
	Rte      []*Rte    `xml:"rte"`
	Trk      []*Trk    `xml:"trk"`
}

Gpx is a root node in .gpx document.

func Parse

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

Parse returns a Gpx struct from gpx stream

func ParseFile

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

ParseFile returns a Gpx struct from gpx file

func (*Gpx) Distance

func (g *Gpx) Distance() float64

Distance returns gpx track distance

type Link struct {
	Href string `xml:"href,attr"`
	Text string `xml:"text"`
	Type string `xml:"type"`
}

Link is a link to external resource with additional information

type Metadata

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

Metadata holds information about .gpx file.

type Person

type Person struct {
	Name  string `xml:"name"`
	Email *Email `xml:"email"`
	Link  *Link  `xml:"link"`
}

Person represents person or organization

type Rte

type Rte struct {
	Name   string  `xml:"name"`
	Cmt    string  `xml:"cmt"`
	Desc   string  `xml:"desc"`
	Src    string  `xml:"src"`
	Link   []*Link `xml:"link"`
	Number uint    `xml:"number"`
	Type   string  `xml:"type"`
	Rtept  []*Wpt  `xml:"rtept"`
}

Rte represents route - an ordered list of waypoints representing a series of turn points leading to a destination.

type Trk

type Trk struct {
	Name   string    `xml:"name"`
	Cmt    string    `xml:"cmt"`
	Desc   string    `xml:"desc"`
	Src    string    `xml:"src"`
	Link   []*Link   `xml:"link"`
	Number uint      `xml:"number"`
	Type   string    `xml:"type"`
	Trkseg []*Trkseg `xml:"trkseg"`
}

Trk represents a track - an ordered list of points describing a path.

type Trkseg

type Trkseg struct {
	Trkpt []*Wpt `xml:"trkpt"`
}

Trkseg holds a list of Track Points which are logically connected in order.

type Wpt

type Wpt struct {
	Lat          float64   `xml:"lat,attr"`
	Lon          float64   `xml:"lon,attr"`
	Ele          float64   `xml:"ele"`
	Time         time.Time `xml:"time"`
	Magvar       float64   `xml:"magvar"`
	GeoIDHeight  float64   `xml:"geoidheight"`
	Name         string    `xml:"name"`
	Cmt          string    `xml:"cmt"`
	Desc         string    `xml:"desc"`
	Src          string    `xml:"src"`
	Link         []*Link   `xml:"link"`
	Sym          string    `xml:"sym"`
	Type         string    `xml:"type"`
	Fix          string    `xml:"fix"` // http://www.topografix.com/gpx/1/1/#type_fixType
	Sat          uint      `xml:"sat"`
	Hdop         float64   `xml:"hdop"`
	Vdop         float64   `xml:"vdop"`
	Pdop         float64   `xml:"pdop"`
	AgeOfGPSData float64   `xml:"ageofgpsdata"`
	DGPSID       uint      `xml:"dgpsid"`
}

Wpt represents a waypoint, point of interest, or named feature on a map.

Jump to

Keyboard shortcuts

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