diff pkg/octree/vertex.go @ 925:15bf101e1522

Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sat, 06 Oct 2018 13:34:51 +0200
parents c8146132059e
children 0a0013fbda4a
line wrap: on
line diff
--- a/pkg/octree/vertex.go	Sat Oct 06 13:20:31 2018 +0200
+++ b/pkg/octree/vertex.go	Sat Oct 06 13:34:51 2018 +0200
@@ -39,7 +39,9 @@
 
 const (
 	wkbNDR              byte   = 1
+	wkbLineString       uint32 = 2
 	wkbLineStringZ      uint32 = 1000 + 2
+	wkbMultiLineString  uint32 = 5
 	wkbMultiLineStringZ uint32 = 1000 + 5
 )
 
@@ -320,6 +322,33 @@
 	return buf.Bytes()
 }
 
+func (mls MultiLineStringZ) AsWKB2D() []byte {
+
+	// pre-calculate size to avoid reallocations.
+	size := 1 + 4 + 4
+	for _, ml := range mls {
+		size += 1 + 4 + 4 + len(ml)*2*8
+	}
+
+	buf := bytes.NewBuffer(make([]byte, 0, size))
+
+	binary.Write(buf, binary.LittleEndian, wkbNDR)
+	binary.Write(buf, binary.LittleEndian, wkbMultiLineString)
+	binary.Write(buf, binary.LittleEndian, uint32(len(mls)))
+
+	for _, ml := range mls {
+		binary.Write(buf, binary.LittleEndian, wkbNDR)
+		binary.Write(buf, binary.LittleEndian, wkbLineString)
+		binary.Write(buf, binary.LittleEndian, uint32(len(ml)))
+		for _, p := range ml {
+			binary.Write(buf, binary.LittleEndian, math.Float64bits(p.X))
+			binary.Write(buf, binary.LittleEndian, math.Float64bits(p.Y))
+		}
+	}
+
+	return buf.Bytes()
+}
+
 func (a Box2D) Intersects(b Box2D) bool {
 	return !(a.X2 < a.X1 || a.X2 < b.X1 ||
 		a.Y2 < a.Y1 || a.Y2 < b.Y1)