gpx

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 5 Imported by: 4

README

gpx

A simple gpx parser (support Strava currently) for running and written in Go.

Installation

$ make dep

Tests

$ make test

Usage

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/neighborhood999/gpx"
)

func main() {
	f, err := os.Open("running.gpx")

	if err != nil {
		fmt.Println(err)
	}

	defer f.Close()

	b, _ := ioutil.ReadAll(f)
	g, _ := gpx.ReadGPX(bytes.NewReader(b))

	fmt.Println(g.Distance()) // Get the total running distance
	fmt.Println(g.Duration()) // Get the total running duration
	fmt.Println(g.PaceInKM()) // Get the running pace(km/min)
}

LICENSE

MIT © Peng Jie

Documentation

Index

Constants

View Source
const EARTHRADIUS = 6371

EARTHRADIUS is the Earth's radius 6,371km. ref: https://en.wikipedia.org/wiki/Earth_radius

Variables

This section is empty.

Functions

This section is empty.

Types

type DGPSStation

type DGPSStation int

DGPSStation is the representation a differential GPS station. (0 <= value <= 1023)

type Degrees

type Degrees float64

Degrees is used for bearing, heading, course. Units are decimal degrees, true (not magnetic). (0.0 <= value < 360.0)

type Extensions

type Extensions struct {
	XML []byte `xml:",innerxml"`
}

Extensions is the representation extension.

type Fix

type Fix string

Fix is the representation type of GPS fix. none means GPS had no fix. To signify "the fix info is unknown, leave out fixType entirely. pps = military signal used (value comes from list: {'none'|'2d'|'3d'|'dgps'|'pps'})

type GPX

type GPX struct {
	XMLName  string    `xml:"gpx"`
	Creator  string    `xml:"creator,attr,omitempty"`
	Version  string    `xml:"version,attr,omitempty"`
	Metadata *MetaData `xml:"metadata,omitempty"`
	Tracks   []Track   `xml:"trk,omitempty"`
}

GPX is the representation gpxType.

func ReadGPX

func ReadGPX(r io.Reader) (*GPX, error)

ReadGPX is a GPX reader and return a GPX object and error.

func (*GPX) Distance

func (g *GPX) Distance() float64

Distance returns total distance

func (*GPX) Duration

func (g *GPX) Duration() float64

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

func (*GPX) Elevations

func (g *GPX) Elevations() []float64

Elevations returns all the track point elevation.

func (*GPX) GetCoordinates

func (g *GPX) GetCoordinates() []Point

GetCoordinates return all track points latitude and longitude.

func (*GPX) MinAndMixElevation

func (g *GPX) MinAndMixElevation() (float64, float64)

MinAndMixElevation returns min and mix elevation.

func (*GPX) PaceInKM

func (g *GPX) PaceInKM() *Pace

PaceInKM returns running pace in kilometers.

func (*GPX) PaceInMile

func (g *GPX) PaceInMile() *Pace

PaceInMile returns running pace in miles.

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 an external resource (Web page, digital photo, video clip, etc) with additional information.

type MetaData

type MetaData struct {
	XMLName   xml.Name `xml:"metadata"`
	Timestamp string   `xml:"time,omitempty"`
}

MetaData is the information about the GPX file, author, and copyright restrictions goes in the metadata section.

type Pace

type Pace struct {
	Minutes int
	Seconds int
}

Pace is the representation a running pace.

type Point added in v0.0.3

type Point struct {
	Latitude  float64
	Longitude float64
}

Point is the representation a point of latitude and longitude

type Track

type Track struct {
	XMLName       xml.Name       `xml:"trk"`
	Name          string         `xml:"name,omitempty"`
	Comment       string         `xml:"cmt,omitempty"`
	Description   string         `xml:"desc,omitempty"`
	Source        string         `xml:"src,omitempty"`
	Links         []Link         `xml:"link,omitempty"`
	Number        int            `xml:"number,omitempty"`
	Type          string         `xml:"type,omitempty"`
	Extensions    *Extensions    `xml:"extensions,omitempty"`
	TrackSegments []TrackSegment `xml:"trkseg,omitempty"`
}

Track is the representation trk - an ordered list of points describing a path.

type TrackPointExtension

type TrackPointExtension struct {
	XMLName      xml.Name `xml:"TrackPointExtension"`
	Temperature  float64  `xml:"atemp,omitempty"`
	WTemperature float64  `xml:"wtemp,omitempty"`
	Depth        float64  `xml:"depth,omitempty"`
	HeartRate    int      `xml:"hr,omitempty"`
	Cadence      int      `xml:"cad,omitempty"`
}

TrackPointExtension tracks temperature, heart rate and cadence specific to devices

type TrackPointExtensions

type TrackPointExtensions struct {
	XMLName              xml.Name             `xml:"extensions"`
	TrackPointExtensions *TrackPointExtension `xml:"TrackPointExtension,omitempty"`
}

TrackPointExtensions extend GPX by adding your own elements from another schema

type TrackSegment

type TrackSegment struct {
	XMLName    xml.Name    `xml:"trkseg"`
	TrackPoint []WayPoint  `xml:"trkpt"`
	Extensions *Extensions `xml:"extensions,omitempty"`
}

TrackSegment holds a list of TrackPoint which are logically connected in order.

type WayPoint

type WayPoint struct {
	XMLName                       xml.Name              `xml:"trkpt"`
	Latitude                      float64               `xml:"lat,attr"`
	Longitude                     float64               `xml:"lon,attr"`
	Elevation                     float64               `xml:"ele,omitempty"`
	Timestamp                     string                `xml:"time,omitempty"`
	MagneticVariation             Degrees               `xml:"magvar,omitempty"`
	GeoIDHeight                   float64               `xml:"geoidheight,omitempty"`
	Name                          string                `xml:"name,omitempty"`
	Comment                       string                `xml:"cmt,omitempty"`
	Description                   string                `xml:"desc,omitempty"`
	Source                        string                `xml:"src,omitempty"`
	Links                         []Link                `xml:"link,omitempty"`
	Symbol                        string                `xml:"sym,omitempty"`
	Type                          string                `xml:"type,omitempty"`
	Fix                           Fix                   `xml:"fix,omitempty"`
	Sat                           int                   `xml:"sat,omitempty"`
	HorizontalDilutionOfPrecision float64               `xml:"hdop,omitempty"`
	VerticalDilutionOfPrecision   float64               `xml:"vdop,omitempty"`
	PositionDilutionOfPrecision   float64               `xml:"pdop,omitempty"`
	AgeOfGpsData                  float64               `xml:"ageofgpsdata,omitempty"`
	DifferentialGPSID             DGPSStation           `xml:"dgpsid,omitempty"`
	Extensions                    *TrackPointExtensions `xml:"extensions,omitempty"`
}

WayPoint is a point of interest, or named feature on a map.

func (*WayPoint) Distance

func (w *WayPoint) Distance(w2 *WayPoint) float64

Distance returns two point distance. ref: https://www.movable-type.co.uk/scripts/latlong.html

func (*WayPoint) Time

func (w *WayPoint) Time() time.Time

Time returns TrackPoint timestamp as Time

Jump to

Keyboard shortcuts

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