Mercurial > gemma
comparison pkg/imports/sr.go @ 3645:02951a62e8c6
'Historicise' bottlenecks on import
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 12 Jun 2019 17:11:15 +0200 |
parents | e1021fd60190 |
children | 2a079d0a71c1 |
comparison
equal
deleted
inserted
replaced
3644:9e91b416d5bb | 3645:02951a62e8c6 |
---|---|
30 "path/filepath" | 30 "path/filepath" |
31 "strconv" | 31 "strconv" |
32 "strings" | 32 "strings" |
33 "time" | 33 "time" |
34 | 34 |
35 "github.com/jackc/pgx" | |
35 shp "github.com/jonas-p/go-shp" | 36 shp "github.com/jonas-p/go-shp" |
36 | 37 |
37 "gemma.intevation.de/gemma/pkg/common" | 38 "gemma.intevation.de/gemma/pkg/common" |
38 "gemma.intevation.de/gemma/pkg/misc" | 39 "gemma.intevation.de/gemma/pkg/misc" |
39 "gemma.intevation.de/gemma/pkg/models" | 40 "gemma.intevation.de/gemma/pkg/models" |
111 bottleneck_id, | 112 bottleneck_id, |
112 date_info, | 113 date_info, |
113 depth_reference, | 114 depth_reference, |
114 area | 115 area |
115 ) SELECT | 116 ) SELECT |
116 (SELECT id from waterway.bottlenecks where objnam = $1), | 117 (SELECT id FROM waterway.bottlenecks WHERE objnam = $1 |
118 AND validity @> CAST($2 AS timestamptz)), | |
117 $2::date, | 119 $2::date, |
118 $3, | 120 $3, |
119 (SELECT | 121 (SELECT |
120 CASE WHEN $5::bytea IS NULL THEN | 122 CASE WHEN $5::bytea IS NULL THEN |
121 ST_Transform(ST_ConcaveHull(ST_Force2D(ST_GeomFromWKB($4, $6::integer)), 0.7), 4326)::geography | 123 ST_Transform(ST_ConcaveHull(ST_Force2D(ST_GeomFromWKB($4, $6::integer)), 0.7), 4326)::geography |
170 grwl.depth_reference | 172 grwl.depth_reference |
171 FROM waterway.gauges_reference_water_levels grwl | 173 FROM waterway.gauges_reference_water_levels grwl |
172 JOIN waterway.bottlenecks bns | 174 JOIN waterway.bottlenecks bns |
173 ON grwl.location = bns.gauge_location | 175 ON grwl.location = bns.gauge_location |
174 AND grwl.validity = bns.gauge_validity | 176 AND grwl.validity = bns.gauge_validity |
175 WHERE bns.objnam = $1 AND grwl.depth_reference like 'LDC%' | 177 WHERE bns.objnam = $1 |
178 AND bns.validity @> CAST($2 AS timestamptz) | |
179 AND grwl.depth_reference like 'LDC%' | |
176 ` | 180 ` |
177 | 181 |
178 reprojectPointsSingleBeamSQL = ` | 182 reprojectPointsSingleBeamSQL = ` |
179 SELECT | 183 SELECT |
180 ST_AsBinary( | 184 ST_AsBinary( |
224 | 228 |
225 if m.DepthReference == "ZPG" { | 229 if m.DepthReference == "ZPG" { |
226 feedback.Info("Found ZPG as reference system -> translating Z values to LDC") | 230 feedback.Info("Found ZPG as reference system -> translating Z values to LDC") |
227 var ldc float64 | 231 var ldc float64 |
228 var depthReference string | 232 var depthReference string |
229 err := conn.QueryRowContext(ctx, selectGaugeLDCSQL, m.Bottleneck).Scan( | 233 err := conn.QueryRowContext(ctx, |
234 selectGaugeLDCSQL, | |
235 m.Bottleneck, | |
236 m.Date.Time, | |
237 ).Scan( | |
230 &ldc, | 238 &ldc, |
231 &depthReference, | 239 &depthReference, |
232 ) | 240 ) |
233 switch { | 241 switch { |
234 case err == sql.ErrNoRows: | 242 case err == sql.ErrNoRows: |
410 &hull, | 418 &hull, |
411 ) | 419 ) |
412 xyz, boundary = nil, nil // not need from now on. | 420 xyz, boundary = nil, nil // not need from now on. |
413 feedback.Info("Calculating hull took %s.", time.Since(start)) | 421 feedback.Info("Calculating hull took %s.", time.Since(start)) |
414 if err != nil { | 422 if err != nil { |
423 if e, isPgErr := err.(pgx.PgError); isPgErr && | |
424 e.Code == notNullViolation && | |
425 e.SchemaName == "waterway" && | |
426 e.TableName == "sounding_results" && | |
427 e.ColumnName == "bottleneck_id" { | |
428 return nil, fmt.Errorf( | |
429 "No bottleneck matching given name and time available") | |
430 } | |
415 return nil, err | 431 return nil, err |
416 } | 432 } |
417 feedback.Info("Best suited UTM EPSG: %d", epsg) | 433 feedback.Info("Best suited UTM EPSG: %d", epsg) |
418 | 434 |
419 start = time.Now() | 435 start = time.Now() |