-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
line_string.go
96 lines (84 loc) · 2.2 KB
/
line_string.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package wkb
import (
"encoding/binary"
"fmt"
"io"
"github.com/terranodo/tegola"
)
// LineString describes a line, that is made up of two or more points
type LineString []Point
// Type returns the type constant for a LineString
func (LineString) Type() uint32 {
return GeoLineString
}
// Decode will decode the binary representation into a LineString Object.
func (ls *LineString) Decode(bom binary.ByteOrder, r io.Reader) error {
var num uint32
if err := binary.Read(r, bom, &num); err != nil {
return err
}
for i := 0; i < int(num); i++ {
var p = new(Point)
if err := p.Decode(bom, r); err != nil {
return err
}
*ls = append(*ls, *p)
}
return nil
}
// Subpoints returns a copy of the points that make up the Line.
func (ls *LineString) Subpoints() (pts []tegola.Point) {
if ls == nil || len(*ls) == 0 {
return pts
}
for i := range *ls {
pts = append(pts, &((*ls)[i]))
}
return pts
}
//String returns the WKT representation of the Geometry
func (ls *LineString) String() string {
return WKT(ls) // If we have a failure we don't care
}
//MultiLineString represents one or more independent lines.
type MultiLineString []LineString
//Type returns the Type constant for a Multiline String.
func (MultiLineString) Type() uint32 {
return GeoMultiLineString
}
//Lines return the indivual lines in the grouping.
func (ml *MultiLineString) Lines() (lns []tegola.LineString) {
if ml == nil || len(*ml) == 0 {
return lns
}
for i := range *ml {
lns = append(lns, &((*ml)[i]))
}
return lns
}
//Decode takes a byteOrder and an io.Reader, to decode the stream.
func (ml *MultiLineString) Decode(bom binary.ByteOrder, r io.Reader) error {
var num uint32
if err := binary.Read(r, bom, &num); err != nil {
return err
}
for i := uint32(0); i < num; i++ {
var l = new(LineString)
byteOrder, typ, err := decodeByteOrderType(r)
if err != nil {
return err
}
if typ != GeoLineString {
return fmt.Errorf("Expect Multilines to contains lines; did not find a line.")
}
if err := l.Decode(byteOrder, r); err != nil {
return err
}
*ml = append(*ml, *l)
}
return nil
}
//String returns the WKT representation of the Geometry.
func (ml *MultiLineString) String() string {
return WKT(ml)
}