# HG changeset patch # User Sascha L. Teichmann # Date 1549039179 -3600 # Node ID 7a3378c14397471f877d9413c571c0b9a2151f1d # Parent a9d28c4897610926df55043a4020eb2a37baebe1 Waterway profiles import: Added a precision parameter in meters to find lines for points (default 10m). diff -r a9d28c489761 -r 7a3378c14397 pkg/controllers/wpimports.go --- 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) diff -r a9d28c489761 -r 7a3378c14397 pkg/imports/wp.go --- 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 }