# HG changeset patch # User Sascha L. Teichmann # Date 1538825691 -7200 # Node ID 15bf101e1522d8cc6bdd1167e73de64537128377 # Parent c8146132059e30beb7f8ddd78b7b1a2cbec85bd6 Send 2D X/Y vertices to the database directly instead of sending 3D data and dropping the Z value afterwards. diff -r c8146132059e -r 15bf101e1522 cmd/octree2contour/store.go --- 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 { diff -r c8146132059e -r 15bf101e1522 pkg/octree/vertex.go --- 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)