Documentation ¶
Overview ¶
Package gpx provides convenience types for reading and writing GPX documents. See http://www.topografix.com/gpx.asp.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var StartElement = xml.StartElement{ Name: xml.Name{Local: "gpx"}, }
StartElement is the XML start element for GPX files.
Functions ¶
This section is empty.
Types ¶
type BoundsType ¶
type BoundsType struct { MinLat float64 `xml:"minlat,attr"` MinLon float64 `xml:"minlon,attr"` MaxLat float64 `xml:"maxlat,attr"` MaxLon float64 `xml:"maxlon,attr"` }
A BoundsType is a boundsType.
type CopyrightType ¶
type CopyrightType struct { Author string `xml:"author,attr"` Year int `xml:"year,omitempty"` License string `xml:"license,omitempty"` }
A CopyrightType is a copyrightType.
func (*CopyrightType) UnmarshalXML ¶
func (c *CopyrightType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML implements xml.Unmarshaler.UnmarshalXML.
type ExtensionsType ¶
type ExtensionsType struct {
XML []byte `xml:",innerxml"`
}
An ExtensionsType contains elements from another schema.
type GPX ¶
type GPX struct { XMLName string `xml:"gpx"` XMLSchemaLoctions []string `xml:"xsi:schemaLocation,attr"` XMLAttrs map[string]string `xml:"-"` Version string `xml:"version,attr"` Creator string `xml:"creator,attr"` Metadata *MetadataType `xml:"metadata,omitempty"` Wpt []*WptType `xml:"wpt,omitempty"` Rte []*RteType `xml:"rte,omitempty"` Trk []*TrkType `xml:"trk,omitempty"` Extensions *ExtensionsType `xml:"extensions"` }
A GPX is a gpxType.
func Read ¶
Read reads a new GPX from r.
Example ¶
package main import ( "bytes" "fmt" gpx "github.com/twpayne/go-gpx" ) func main() { r := bytes.NewBufferString(` <?xml version="1.0" encoding="UTF-8"?> <gpx version="1.0" creator="ExpertGPS 1.1 - http://www.topografix.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> <wpt lat="42.438878" lon="-71.119277"> <ele>44.586548</ele> <speed>9.16</speed> <time>2001-11-28T21:05:28Z</time> <name>5066</name> <desc>5066</desc> <sym>Crossing</sym> <type>Crossing</type> </wpt> </gpx> `) t, err := gpx.Read(r) if err != nil { fmt.Printf("err == %v", err) return } fmt.Printf("t.Wpt[0] == %+v", t.Wpt[0]) }
Output: t.Wpt[0] == &{Lat:42.438878 Lon:-71.119277 Ele:44.586548 Speed:9.16 Course:0 Time:2001-11-28 21:05:28 +0000 UTC MagVar:0 GeoidHeight:0 Name:5066 Cmt: Desc:5066 Src: Link:[] Sym:Crossing Type:Crossing Fix: Sat:0 HDOP:0 VDOP:0 PDOP:0 AgeOfDGPSData:0 DGPSID:[] Extensions:<nil>}
func (*GPX) MarshalXML ¶
MarshalXML implements xml.Marshaler.MarshalXML.
func (*GPX) WriteIndent ¶
WriteIndent writes g to w.
Example ¶
package main import ( "encoding/xml" "fmt" "os" "time" gpx "github.com/twpayne/go-gpx" ) func main() { g := &gpx.GPX{ Version: "1.0", Creator: "ExpertGPS 1.1 - http://www.topografix.com", Wpt: []*gpx.WptType{ { Lat: 42.438878, Lon: -71.119277, Ele: 44.586548, Time: time.Date(2001, 11, 28, 21, 5, 28, 0, time.UTC), Name: "5066", Desc: "5066", Sym: "Crossing", Type: "Crossing", }, }, } if _, err := os.Stdout.WriteString(xml.Header); err != nil { fmt.Printf("err == %v", err) } if err := g.WriteIndent(os.Stdout, "", " "); err != nil { fmt.Printf("err == %v", err) } }
Output: <?xml version="1.0" encoding="UTF-8"?> <gpx version="1.0" creator="ExpertGPS 1.1 - http://www.topografix.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> <wpt lat="42.438878" lon="-71.119277"> <ele>44.586548</ele> <time>2001-11-28T21:05:28Z</time> <name>5066</name> <desc>5066</desc> <sym>Crossing</sym> <type>Crossing</type> </wpt> </gpx>
type LinkType ¶
type LinkType struct { HREF string `xml:"href,attr"` Text string `xml:"text,omitempty"` Type string `xml:"type,omitempty"` }
A LinkType is a linkType.
type MetadataType ¶
type MetadataType struct { Name string `xml:"name,omitempty"` Desc string `xml:"desc,omitempty"` Author *PersonType `xml:"author,omitempty"` Copyright *CopyrightType `xml:"copyright,omitempty"` Link []*LinkType `xml:"link,omitempty"` Time time.Time `xml:"time,omitempty"` Keywords string `xml:"keywords,omitempty"` Bounds *BoundsType `xml:"bounds,omitempty"` Extensions *ExtensionsType `xml:"extensions"` }
A MetadataType is a metadataType.
type PersonType ¶
type PersonType struct { Name string `xml:"name,omitempty"` Email string `xml:"email,omitempty"` Link *LinkType `xml:"link,omitempty"` }
A PersonType is a personType.
type RteType ¶
type RteType struct { Name string `xml:"name,omitempty"` Cmt string `xml:"cmt,omitempty"` Desc string `xml:"desc,omitempty"` Src string `xml:"src,omitempty"` Link []*LinkType `xml:"link,omitempty"` Number int `xml:"number,omitempty"` Type string `xml:"type,omitempty"` Extensions *ExtensionsType `xml:"extensions"` RtePt []*WptType `xml:"rtept,omitempty"` }
A RteType is a rteType.
func NewRteType ¶
func NewRteType(g *geom.LineString) *RteType
NewRteType returns a new RteType with geometry g.
type TrkSegType ¶
type TrkSegType struct { TrkPt []*WptType `xml:"trkpt,omitempty"` Extensions *ExtensionsType `xml:"extensions"` }
A TrkSegType is a trkSegType.
func NewTrkSegType ¶
func NewTrkSegType(g *geom.LineString) *TrkSegType
NewTrkSegType returns a new TrkSegType with geometry g.
func (*TrkSegType) Geom ¶
func (ts *TrkSegType) Geom(layout geom.Layout) *geom.LineString
Geom returns ts's geometry.
type TrkType ¶
type TrkType struct { Name string `xml:"name,omitempty"` Cmt string `xml:"cmt,omitempty"` Desc string `xml:"desc,omitempty"` Src string `xml:"src,omitempty"` Link []*LinkType `xml:"link,omitempty"` Number int `xml:"number,omitempty"` Type string `xml:"type,omitempty"` Extensions *ExtensionsType `xml:"extensions"` TrkSeg []*TrkSegType `xml:"trkseg,omitempty"` }
A TrkType is a trkType.
func NewTrkType ¶
func NewTrkType(g *geom.MultiLineString) *TrkType
NewTrkType returns a new TrkType with geometry g.
type WptType ¶
type WptType struct { Lat float64 Lon float64 Ele float64 Speed float64 Course float64 Time time.Time MagVar float64 GeoidHeight float64 Name string Cmt string Desc string Src string Link []*LinkType Sym string Type string Fix string Sat int HDOP float64 VDOP float64 PDOP float64 AgeOfDGPSData float64 DGPSID []int Extensions *ExtensionsType }
A WptType is a wptType.
func NewWptType ¶
NewWptType returns a new WptType with geometry g.
func (*WptType) MarshalXML ¶
MarshalXML implements xml.Marshaler.MarshalXML.
func (*WptType) UnmarshalXML ¶
UnmarshalXML implements xml.Unmarshaler.UnmarshalXML.