forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection.go
51 lines (41 loc) · 915 Bytes
/
collection.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
package wkb
import (
"io"
"github.com/dadadamarine/orb"
)
func readCollection(r io.Reader, order byteOrder, buf []byte) (orb.Collection, error) {
num, err := readUint32(r, order, buf[:4])
if err != nil {
return nil, err
}
alloc := num
if alloc > maxMultiAlloc {
// invalid data can come in here and allocate tons of memory.
alloc = maxMultiAlloc
}
result := make(orb.Collection, 0, alloc)
d := NewDecoder(r)
for i := 0; i < int(num); i++ {
geom, err := d.Decode()
if err != nil {
return nil, err
}
result = append(result, geom)
}
return result, nil
}
func (e *Encoder) writeCollection(c orb.Collection) error {
e.order.PutUint32(e.buf, geometryCollectionType)
e.order.PutUint32(e.buf[4:], uint32(len(c)))
_, err := e.w.Write(e.buf[:8])
if err != nil {
return err
}
for _, geom := range c {
err := e.Encode(geom)
if err != nil {
return err
}
}
return nil
}