Mercurial > gemma
changeset 5008:0b97f5301a17
Add a multiLineSlice type to be serialized as WKB in importers.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 11 Mar 2020 15:54:37 +0100 |
parents | 799e8248de8d |
children | e8b2dc771f9e |
files | pkg/imports/wkb.go |
diffstat | 1 files changed, 34 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/wkb.go Wed Mar 11 14:23:52 2020 +0100 +++ b/pkg/imports/wkb.go Wed Mar 11 15:54:37 2020 +0100 @@ -25,21 +25,17 @@ ) type ( - pointSlice []float64 - lineSlice [][]float64 - polygonSlice [][][]float64 + pointSlice []float64 + lineSlice [][]float64 + multiLineSlice []lineSlice + polygonSlice [][][]float64 ) func newPointFeature(newProperties func() interface{}) func() (string, interface{}) { return func() (string, interface{}) { return "Point", newProperties() } } -func (ls lineSlice) asWKB() []byte { - - size := 1 + 4 + 4 + len(ls)*(2*8) - - buf := bytes.NewBuffer(make([]byte, 0, size)) - +func (ls lineSlice) toWKB(buf *bytes.Buffer) { binary.Write(buf, binary.LittleEndian, wkb.NDR) binary.Write(buf, binary.LittleEndian, wkb.LineString) binary.Write(buf, binary.LittleEndian, uint32(len(ls))) @@ -55,6 +51,14 @@ binary.Write(buf, binary.LittleEndian, math.Float64bits(lat)) binary.Write(buf, binary.LittleEndian, math.Float64bits(lon)) } +} + +func (ls lineSlice) asWKB() []byte { + + size := 1 + 4 + 4 + len(ls)*(2*8) + + buf := bytes.NewBuffer(make([]byte, 0, size)) + ls.toWKB(buf) return buf.Bytes() } @@ -68,6 +72,27 @@ return lr } +func (mls multiLineSlice) asWKB() []byte { + + size := 1 + 4 + 4 + + for _, ls := range mls { + size += 1 + 4 + 4 + len(ls)*(2*8) + } + + buf := bytes.NewBuffer(make([]byte, 0, size)) + + binary.Write(buf, binary.LittleEndian, wkb.NDR) + binary.Write(buf, binary.LittleEndian, wkb.MultiLineString) + binary.Write(buf, binary.LittleEndian, uint32(len(mls))) + + for _, ls := range mls { + ls.toWKB(buf) + } + + return buf.Bytes() +} + func (p pointSlice) asWKB() []byte { size := 1 + 4 + 2*8