-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (49 loc) · 1.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"log"
"os"
)
func main() {
// Flags handling
metadataName := flag.String("m", "Merged GPX", "String used in <metadata><name>")
trackName := flag.String("t", "Merged track", "String used in <trk><name>")
outfname := flag.String("o", "", "Output file")
flag.Parse()
if len(*outfname) == 0 {
log.Println("No output filename specified")
os.Exit(1)
}
// Read input GPXs
inp_gpxs := make([]GPX, flag.NArg())
ntrkpts := 0
for i, fname := range flag.Args() {
fi, err := os.Open(fname)
if err != nil {
log.Fatal(err)
}
defer fi.Close()
if err := inp_gpxs[i].Read(fi); err != nil {
log.Fatal(err)
}
ntrkpts += len(inp_gpxs[i].Track.TrackSegment)
}
// Struct which is used for merging all the trackpoints
out_gpx := GPX{}
out_gpx.Metadata.Name = *metadataName
out_gpx.Track.Name = *trackName
out_gpx.Track.TrackSegment = make([]TrackPoint, ntrkpts)
// Performs the merging
i := 0
for _, gpx := range inp_gpxs {
copy(out_gpx.Track.TrackSegment[i:i+len(gpx.Track.TrackSegment)], gpx.Track.TrackSegment)
i += len(gpx.Track.TrackSegment)
}
// Writes output file
fo, err := os.Create(*outfname)
if err != nil {
log.Fatal(err)
}
defer fo.Close()
out_gpx.Write(fo)
}