diff pkg/imports/sr.go @ 977:4a2ca0e20006

Fixed build error. Copied file to the wrong place and said 'go build' to another wrong place. Argh.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 18 Oct 2018 17:30:53 +0200
parents c397fdd8c327
children 544a5cfe07cd
line wrap: on
line diff
--- a/pkg/imports/sr.go	Thu Oct 18 17:05:54 2018 +0200
+++ b/pkg/imports/sr.go	Thu Oct 18 17:30:53 2018 +0200
@@ -42,6 +42,11 @@
 )
 
 const (
+	contourStepWidth = 0.5
+	contourTolerance = 0.1
+)
+
+const (
 	insertPointsSQL = `
 INSERT INTO waterway.sounding_results (
   bottleneck_id,
@@ -80,6 +85,34 @@
   $2,
   $3
 )`
+
+	insertContourSQL = `
+INSERT INTO waterway.sounding_results_contour_lines (
+  sounding_result_id,
+  height,
+  lines
+)
+SELECT
+  $1,
+  $2,
+  ST_Transform(
+    ST_Multi(
+      ST_CollectionExtract(
+        ST_Intersection(
+          ST_Transform(sr.area::geometry, $3::integer),
+          ST_SimplifyPreserveTopology(
+            ST_GeomFromWKB($4, $3::integer),
+            $5
+          )
+        ),
+        2
+      )
+    ),
+    4326
+  )
+FROM waterway.sounding_results sr
+WHERE id = $1
+`
 )
 
 func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error {
@@ -354,3 +387,22 @@
 
 	return tx.Commit()
 }
+
+func generateContours(tree *octree.Tree, tx *sql.Tx, id int64) error {
+	stmt, err := tx.Prepare(insertContourSQL)
+	if err != nil {
+		return err
+	}
+	defer stmt.Close()
+
+	octree.DoContours(tree, contourStepWidth, func(res *octree.ContourResult) {
+		if err == nil {
+			_, err = stmt.Exec(
+				id, res.Height, tree.EPSG,
+				res.Lines.AsWKB2D(),
+				contourTolerance)
+		}
+	})
+
+	return err
+}