-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_line_string.go
106 lines (87 loc) · 2.28 KB
/
multi_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
97
98
99
100
101
102
103
104
105
106
package ewkb
import (
"database/sql/driver"
"errors"
"fmt"
"github.com/kcasctiv/go-ewkb/geo"
)
// MultiLineString presents MultiLineString geometry object
type MultiLineString struct {
header
ml geo.MultiLine
}
// NewMultiLineString returns new MultiLineString,
// created from geometry base and coords data
func NewMultiLineString(b Base, ml geo.MultiLine) MultiLineString {
return MultiLineString{
header: header{
byteOrder: b.ByteOrder(),
wkbType: getFlags(
b.HasZ(),
b.HasM(),
b.HasSRID(),
) | MultiLineType,
srid: b.SRID(),
},
ml: ml,
}
}
// Line returns line with specified index
func (l *MultiLineString) Line(idx int) geo.MultiPoint { return l.ml.Line(idx) }
// Len returns count of lines
func (l *MultiLineString) Len() int { return l.ml.Len() }
// String returns WKT/EWKT geometry representation
func (l *MultiLineString) String() string {
var s string
if l.HasSRID() {
s = fmt.Sprintf("SRID=%d;", l.srid)
}
s += "MULTILINESTRING"
if !l.HasZ() && l.HasM() {
s += "M"
}
if l.Len() == 0 {
s += " EMPTY"
return s
}
s += "("
if l.Len() > 0 {
for idx := 0; idx < l.Len(); idx++ {
s += printMultiPoint(l.Line(idx), l.HasZ(), l.HasM()) + ","
}
s = s[:len(s)-1]
}
return s + ")"
}
// Scan implements sql.Scanner interface
func (l *MultiLineString) Scan(src interface{}) error {
return scanGeometry(src, l)
}
// Value implements sql driver.Valuer interface
func (l *MultiLineString) Value() (driver.Value, error) {
return l.String(), nil
}
// UnmarshalBinary implements encoding.BinaryUnmarshaler interface
func (l *MultiLineString) UnmarshalBinary(data []byte) error {
h, byteOrder, offset := readHeader(data)
if h.Type() != MultiLineType {
return errors.New("not expected geometry type")
}
l.header = h
var err error
l.ml, _, err = readMultiLine(
data[offset:],
byteOrder,
getReadPointFunc(h.wkbType),
)
return err
}
// MarshalBinary implements encoding.BinaryMarshaler interface
func (l *MultiLineString) MarshalBinary() ([]byte, error) {
size := headerSize(l.HasSRID()) + multiLineSize(l, l.HasZ(), l.HasM())
b := make([]byte, size)
byteOrder := getBinaryByteOrder(l.ByteOrder())
offset := writeHeader(l, l.Type(), byteOrder, l.HasSRID(), b)
writeMultiLine(l, byteOrder, l.HasZ(), l.HasM(), b[offset:])
return b, nil
}