forked from patrickbr/gtfsparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.go
66 lines (54 loc) · 1.43 KB
/
shape.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
59
60
61
62
63
64
65
66
// Copyright 2015 geOps
// Authors: patrick.brosi@geops.de
//
// Use of this source code is governed by a GPL v2
// license that can be found in the LICENSE file
package gtfs
import (
"strconv"
)
// A Shape describes the geographical path of one or multiple trips
type Shape struct {
Id string
Points ShapePoints
}
// A ShapePoint is a single point in a Shape
type ShapePoint struct {
Lat float32
Lon float32
Sequence int
Dist_traveled float32
Has_dist bool
}
// Get a string representation of a ShapePoint
func (p *ShapePoint) String() string {
return strconv.FormatFloat(float64(p.Lat), 'f', 8, 32) + "," + strconv.FormatFloat(float64(p.Lon), 'f', 8, 32)
}
// Get a string representation of this shape
func (shape *Shape) String() string {
ret := ""
first := true
for _, point := range shape.Points {
if !first {
ret += "\n"
}
first = false
ret += point.String()
}
return ret
}
// ShapePoints are multiple ShapePoints
type ShapePoints []ShapePoint
func (shapePoints ShapePoints) Len() int {
return len(shapePoints)
}
func (shapePoints ShapePoints) Less(i, j int) bool {
return shapePoints[i].Sequence < shapePoints[j].Sequence
}
func (shapePoints ShapePoints) Swap(i, j int) {
shapePoints[i], shapePoints[j] = shapePoints[j], shapePoints[i]
}
// HasDistanceTraveled returns true if this ShapePoint has a measurement
func (p *ShapePoint) HasDistanceTraveled() bool {
return p.Has_dist
}