changeset 763:d05bc3e34338

More infrastructure for the octree driven cross section endpoint.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 25 Sep 2018 13:11:33 +0200
parents 01ba06da8f46
children a6a8fe89eb84
files pkg/controllers/octreecross.go pkg/octree/vertex.go
diffstat 2 files changed, 62 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/octreecross.go	Tue Sep 25 10:35:17 2018 +0200
+++ b/pkg/controllers/octreecross.go	Tue Sep 25 13:11:33 2018 +0200
@@ -29,6 +29,16 @@
 	return dst, nil
 }
 
+func projectBack(
+	rp *models.Reprojector,
+	lines octree.MultiLineStringZ,
+	ctx context.Context,
+) (models.GeoJSONMultiLineCoordinatesZ, error) {
+	// TODO: Implement me!
+	log.Println("projectBack is not implemented, yet!")
+	return nil, nil
+}
+
 func octreeCrossSection(
 	input interface{},
 	req *http.Request,
@@ -70,17 +80,49 @@
 		return
 	}
 
+	start = time.Now()
+
+	var segments octree.MultiLineStringZ
+
 	for i := 0; i < len(coords)-1; i++ {
-		start = time.Now()
-		var count int
 		c1 := &coords[i]
 		c2 := &coords[i+1]
-		tree.Vertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon, func(*octree.Triangle) {
-			// TODO: Do real intersection.
-			count++
+
+		var line octree.MultiLineStringZ
+		tree.Vertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon, func(t *octree.Triangle) {
+
+			if ls := t.IntersectVertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon); len(ls) > 0 {
+				line = append(line)
+			}
 		})
-		log.Printf("octree traversal took: %s\n", time.Since(start))
-		log.Printf("triangles to intersect: %d\n", count)
+
+		if len(line) > 0 {
+			// They are all on the segment (c1.Lat, c1.Lon) - (c2.Lat, c2.Lon).
+			// Sort them by project them on this line.
+			segments = append(segments, line.JoinOnLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon)...)
+		}
+
+	}
+	log.Printf("octree traversal took: %s\n", time.Since(start))
+	start = time.Now()
+
+	var joined models.GeoJSONMultiLineCoordinatesZ
+	joined, err = projectBack(rp, segments, req.Context())
+
+	log.Printf("projecting back took: %s\n", time.Since(start))
+	if err != nil {
+		return
+	}
+
+	jr = JSONResult{
+		Result: &models.CrossSectionOutput{
+			Type: "Feature",
+			Geometry: models.CrossSectionOutputGeometry{
+				Type:        "MultiLineString",
+				Coordinates: joined,
+			},
+			Properties: map[string]interface{}{},
+		},
 	}
 
 	return
--- a/pkg/octree/vertex.go	Tue Sep 25 10:35:17 2018 +0200
+++ b/pkg/octree/vertex.go	Tue Sep 25 13:11:33 2018 +0200
@@ -4,6 +4,7 @@
 	"bytes"
 	"encoding/binary"
 	"io"
+	"log"
 	"math"
 )
 
@@ -154,6 +155,18 @@
 	return points
 }
 
+func (t *Triangle) IntersectVertical(x1, y1, x2, y2 float64) LineStringZ {
+	// TODO: Implement me!
+	log.Println("Triangle.IntersectVertical is not implemented, yet!")
+	return nil
+}
+
+func (mls MultiLineStringZ) JoinOnLine(x1, y1, x2, y2 float64) MultiLineStringZ {
+	// TODO: Implement me!
+	log.Println("MultiLineStringZ.JoinOnLine is not implemented, yet!")
+	return mls
+}
+
 func (v *Vertex) Write(w io.Writer) error {
 	if err := binary.Write(
 		w, binary.LittleEndian, math.Float64bits(v.X)); err != nil {