Mercurial > gemma
diff pkg/imports/sr.go @ 3656:2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 13 Jun 2019 19:13:42 +0200 |
parents | 02951a62e8c6 |
children | 66f2cb789905 |
line wrap: on
line diff
--- a/pkg/imports/sr.go Thu Jun 13 11:20:17 2019 +0200 +++ b/pkg/imports/sr.go Thu Jun 13 19:13:42 2019 +0200 @@ -32,7 +32,6 @@ "strings" "time" - "github.com/jackc/pgx" shp "github.com/jonas-p/go-shp" "gemma.intevation.de/gemma/pkg/common" @@ -110,12 +109,13 @@ insertHullSQL = ` INSERT INTO waterway.sounding_results ( bottleneck_id, + bottleneck_validity, date_info, depth_reference, area ) SELECT - (SELECT id FROM waterway.bottlenecks WHERE objnam = $1 - AND validity @> CAST($2 AS timestamptz)), + bottleneck_id, + validity, $2::date, $3, (SELECT @@ -124,6 +124,8 @@ ELSE ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326)::geography END) +FROM waterway.bottlenecks +WHERE objnam = $1 AND validity @> CAST($2 AS timestamptz) RETURNING id, ST_X(ST_Centroid(area::geometry)), @@ -419,15 +421,11 @@ ) xyz, boundary = nil, nil // not need from now on. feedback.Info("Calculating hull took %s.", time.Since(start)) - if err != nil { - if e, isPgErr := err.(pgx.PgError); isPgErr && - e.Code == notNullViolation && - e.SchemaName == "waterway" && - e.TableName == "sounding_results" && - e.ColumnName == "bottleneck_id" { - return nil, fmt.Errorf( - "No bottleneck matching given name and time available") - } + switch { + case err == sql.ErrNoRows: + return nil, fmt.Errorf( + "No bottleneck matching given name and time available") + case err != nil: return nil, err } feedback.Info("Best suited UTM EPSG: %d", epsg)