changeset 2094:7a3378c14397

Waterway profiles import: Added a precision parameter in meters to find lines for points (default 10m).
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 01 Feb 2019 17:39:39 +0100
parents a9d28c489761
children 98f0c7956128
files pkg/controllers/wpimports.go pkg/imports/wp.go
diffstat 2 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/wpimports.go	Fri Feb 01 17:18:49 2019 +0100
+++ b/pkg/controllers/wpimports.go	Fri Feb 01 17:39:39 2019 +0100
@@ -15,12 +15,14 @@
 
 import (
 	"bufio"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"log"
 	"net/http"
 	"os"
 	"path/filepath"
+	"strconv"
 	"time"
 
 	"gemma.intevation.de/gemma/pkg/auth"
@@ -93,11 +95,24 @@
 
 	sortBy := req.FormValue("sort-by")
 
+	var precision *float64
+	if p := req.FormValue("precision"); p != "" {
+		if v, err := strconv.ParseFloat(p, 64); err != nil {
+			http.Error(rw,
+				fmt.Sprintf("Invalid 'precision' parameter: %v", err),
+				http.StatusBadRequest)
+			return
+		} else {
+			precision = &v
+		}
+	}
+
 	wp := &imports.WaterwayProfiles{
 		Dir:         dir,
 		URL:         url,
 		FeatureType: featureType,
 		SortBy:      sortBy,
+		Precision:   precision,
 	}
 
 	serialized, err := common.ToJSONString(wp)
--- a/pkg/imports/wp.go	Fri Feb 01 17:18:49 2019 +0100
+++ b/pkg/imports/wp.go	Fri Feb 01 17:39:39 2019 +0100
@@ -36,6 +36,10 @@
 	"gemma.intevation.de/gemma/pkg/wfs"
 )
 
+// defaultPointToLinePrecision is the precision in meters
+// to match from points to lines.
+const defaultPointToLinePrecision = 10
+
 type WaterwayProfiles struct {
 	Dir string `json:"dir"`
 	// URL the GetCapabilities URL of the WFS service.
@@ -45,6 +49,8 @@
 	// SortBy works around misconfigured services to
 	// establish a sort order to get the features.
 	SortBy string `json:"sort-by"`
+	// Precsion of match points to line strings.
+	Precision *float64 `json:"precision,omitempty"`
 }
 
 const WPJobKind JobKind = "wp"
@@ -94,7 +100,7 @@
 	insertWaterwayProfileSQL = `
 WITH point AS (
   SELECT
-    ST_Buffer(geom, 10) AS geom,
+	ST_Buffer(geom, $14::float) AS geom,
     geom                AS point
   FROM waterway.distance_marks_virtual
   WHERE location_code =
@@ -400,6 +406,18 @@
 			strings.Join(missing, ", "))
 	}
 
+	var precision float64
+	if wp.Precision != nil {
+		if precision = *wp.Precision; precision < 0 {
+			precision = -precision
+		}
+	} else {
+		precision = defaultPointToLinePrecision
+	}
+
+	feedback.Info(
+		"Matching points to lines with a precision of %.4fm.", precision)
+
 	parseDate := misc.TimeGuesser([]string{"02.01.2006"}).Guess
 
 	insertStmt, err := tx.PrepareContext(ctx, insertWaterwayProfileSQL)
@@ -526,6 +544,7 @@
 			fe100,
 			dateInfo,
 			source,
+			precision,
 		).Scan(&id, &noGeom); err != nil {
 			return nil, err
 		}