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 ¶
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 ¶ added in v1.1.1
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"`
XMLSchemaLocations []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,omitempty"`
}
A GPX is a gpxType.
func Read ¶
func Read(r io.Reader, options ...ReadOption) (*GPX, error)
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.1" creator="ExpertGPS 1.1 - http://www.topografix.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 https://www.topografix.com/GPX/1/1/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.1",
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.1" creator="ExpertGPS 1.1 - http://www.topografix.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 https://www.topografix.com/GPX/1/1/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,omitempty"`
}
A MetadataType is a metadataType.
func (*MetadataType) UnmarshalXML ¶ added in v1.5.0
func (m *MetadataType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML implements xml.Unmarshaler.UnmarshalXML.
type PersonType ¶
type PersonType struct {
Name string `xml:"name,omitempty"`
Email *EmailType `xml:"email,omitempty"`
Link *LinkType `xml:"link,omitempty"`
}
A PersonType is a personType.
type ReadOption ¶ added in v1.5.0
type ReadOption func()
func WithTimeLayout ¶ added in v1.5.0
func WithTimeLayout(layout string) ReadOption
WithTimeLayout applies a custom time layout for the decoding of the GPX source.
func WithTimeLayouts ¶ added in v1.5.0
func WithTimeLayouts(layouts []string) ReadOption
WithTimeLayouts applies a custom time layouts for the decoding of the GPX source.
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,omitempty"`
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,omitempty"`
}
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,omitempty"`
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 `xml:"lat,omitempty"`
Lon float64 `xml:"lon,omitempty"`
Ele float64 `xml:"ele,omitempty"`
Speed float64 `xml:"speed,omitempty"`
Course float64 `xml:"course,omitempty"`
Time time.Time `xml:"time,omitempty"`
MagVar float64 `xml:"magvar,omitempty"`
GeoidHeight float64 `xml:"geoidheight,omitempty"`
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"`
Sym string `xml:"sym,omitempty"`
Type string `xml:"type,omitempty"`
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"`
AgeOfDGPSData float64 `xml:"ageofdgpsdata,omitempty"`
DGPSID []int `xml:"dgpsid,omitempty"`
Extensions *ExtensionsType `xml:"extensions,omitempty"`
}
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.