diff pkg/imports/sr.go @ 3882:37d5c4441c70

Use custom morpho class breaks in sounding result contour generation.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 10 Jul 2019 11:45:55 +0200
parents 98d5dd2f0ca1
children 4b5c4007fc5d
line wrap: on
line diff
--- a/pkg/imports/sr.go	Wed Jul 10 09:47:02 2019 +0200
+++ b/pkg/imports/sr.go	Wed Jul 10 11:45:55 2019 +0200
@@ -614,7 +614,7 @@
 	feedback.Info("Generate contour lines")
 
 	start = time.Now()
-	err = generateContours(ctx, tx, builder.Tree(), id)
+	err = generateContours(ctx, tx, feedback, builder.Tree(), id)
 	if err != nil {
 		return nil, err
 	}
@@ -817,6 +817,7 @@
 func generateContours(
 	ctx context.Context,
 	tx *sql.Tx,
+	feedback Feedback,
 	tree *octree.Tree,
 	id int64,
 ) error {
@@ -826,13 +827,30 @@
 	}
 	defer stmt.Close()
 
-	// Adjust contour lines heights to multiples of contourStepWidth
-	var heights []float64
-	h := contourStepWidth * math.Ceil(tree.Min.Z/contourStepWidth)
-	for ; h <= tree.Max.Z; h += contourStepWidth {
-		heights = append(heights, h)
+	heights, err := octree.LoadClassBreaks(
+		ctx, tx,
+		"morphology_classbreaks",
+	)
+	if err != nil {
+		feedback.Warn("Loading class breaks failed: %v", err)
+		feedback.Info("Using default class breaks")
+		heights = nil
+		h := contourStepWidth * math.Ceil(tree.Min.Z/contourStepWidth)
+		for ; h <= tree.Max.Z; h += contourStepWidth {
+			heights = append(heights, h)
+		}
+	} else {
+		heights = octree.ExtrapolateClassBreaks(heights, tree.Min.Z, tree.Max.Z)
+		heights = octree.InBetweenClassBreaks(heights, 0.05, 2)
 	}
 
+	/*
+		for i, v := range heights {
+			fmt.Printf("%d %.2f\n", i, v)
+		}
+		log.Printf("%.2f - %.2f\n", tree.Min.Z, tree.Max.Z)
+	*/
+
 	octree.DoContours(tree, heights, func(res *octree.ContourResult) {
 		if err == nil && len(res.Lines) > 0 {
 			_, err = stmt.ExecContext(