changeset 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 9e210b00ace9 48f70782400d
files cmd/octree2contour/store.go pkg/octree/vertex.go
diffstat 2 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/octree2contour/store.go	Sat Oct 06 13:20:31 2018 +0200
+++ b/cmd/octree2contour/store.go	Sat Oct 06 13:34:51 2018 +0200
@@ -31,7 +31,7 @@
         ST_Intersection(
           ST_Transform(sr.area::geometry, $3::integer),
           ST_SimplifyPreserveTopology(
-            ST_LineMerge(ST_Force2D(ST_GeomFromWKB($2, $3::integer))),
+            ST_LineMerge(ST_GeomFromWKB($2, $3::integer)),
             $6
           )
         ),
@@ -70,7 +70,7 @@
 
 		for _, r := range all {
 			if _, err := stmt.Exec(
-				r.h, r.lines.AsWKB(), epsg,
+				r.h, r.lines.AsWKB2D(), epsg,
 				bottleneck, date,
 				tol,
 			); err != nil {
--- 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)