changeset 4574:daed8a92024a iso-areas

Generate iso ares for sounding differences, too.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 07 Oct 2019 13:13:14 +0200
parents 26e9846ed69f
children 6415368c2c60
files pkg/controllers/diff.go
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/diff.go	Mon Oct 07 12:37:17 2019 +0200
+++ b/pkg/controllers/diff.go	Mon Oct 07 13:13:14 2019 +0200
@@ -36,6 +36,12 @@
 )
 
 const (
+	// isoCellSize is the side length of a raster cell when tracing
+	// iso areas.
+	isoCellSize = 0.5
+)
+
+const (
 	diffIDSQL = `
 SELECT sd.id FROM
   caching.sounding_differences sd JOIN
@@ -80,6 +86,29 @@
     4326
   )
 `
+	insertDiffIsoAreasQL = `
+INSERT INTO caching.sounding_differences_iso_areas (
+  sounding_differences_id,
+  height,
+  areas
+)
+SELECT
+  $1,
+  $2,
+  ST_Transform(
+    ST_Multi(
+      ST_CollectionExtract(
+        ST_SimplifyPreserveTopology(
+          ST_Multi(ST_Collectionextract(
+            ST_MakeValid(ST_GeomFromWKB($4, $3::integer)), 3)),
+          $5
+        ),
+        3
+      )
+    ),
+    4326
+  )
+`
 )
 
 // Only allow three diffence calculation at once.
@@ -279,6 +308,12 @@
 	}
 	defer stmt.Close()
 
+	var isoStmt *sql.Stmt
+	if isoStmt, err = tx.PrepareContext(ctx, insertDiffIsoAreasQL); err != nil {
+		return
+	}
+	defer isoStmt.Close()
+
 	if err = tx.QueryRowContext(
 		ctx,
 		insertDiffSQL,
@@ -304,6 +339,22 @@
 		}
 	})
 
+	areas := tree.TraceAreas(heights, isoCellSize)
+
+	for i, a := range areas {
+		if len(a) == 0 {
+			continue
+		}
+		if _, err = isoStmt.ExecContext(
+			ctx,
+			id, heights[i], minuendTree.EPSG,
+			a.AsWKB(),
+			contourTolerance,
+		); err != nil {
+			return
+		}
+	}
+
 	log.Printf("info: calculating and storing iso lines took %v\n",
 		time.Since(start))