1
0
Fork 0
mirror of https://github.com/Luzifer/gpxhydrant.git synced 2024-11-14 01:52:43 +00:00
gpxhydrant/gpx/gpx.go

47 lines
1.2 KiB
Go
Raw Normal View History

2016-05-06 23:32:32 +00:00
package gpx
import (
"encoding/xml"
"io"
"time"
)
2016-05-07 13:17:14 +00:00
// GPX represents the contents of an GPX file
2016-05-06 23:32:32 +00:00
type GPX struct {
XMLName xml.Name `xml:"gpx"`
Metadata struct {
Link struct {
Href string `xml:"href,attr"`
Text string `xml:"text"`
} `xml:"link"`
Time time.Time `xml:"time"`
Bounds struct {
MaxLat float64 `xml:"maxlat,attr"`
MaxLon float64 `xml:"maxlon,attr"`
MinLat float64 `xml:"minlat,attr"`
MinLon float64 `xml:"minlon,attr"`
} `xml:"bounds"`
} `xml:"metadata"`
Waypoints []Waypoint `xml:"wpt"`
}
2016-05-07 13:17:14 +00:00
// Waypoint represents a single waypoint inside a GPX file
2016-05-06 23:32:32 +00:00
type Waypoint struct {
XMLName xml.Name `xml:"wpt"`
Latitude float64 `xml:"lat,attr"`
Longitude float64 `xml:"lon,attr"`
Elevation float64 `xml:"ele"`
Time time.Time `xml:"time"`
Name string `xml:"name"`
Comment string `xml:"cmt"`
Description string `xml:"desc"`
Symbol string `xml:"sym"`
Type string `xml:"type"`
}
2016-05-07 13:17:14 +00:00
// ParseGPXData reads the contents of the GPX file and returns a parsed version
2016-05-06 23:32:32 +00:00
func ParseGPXData(in io.Reader) (*GPX, error) {
out := &GPX{}
return out, xml.NewDecoder(in).Decode(out)
}