Mercurial > gemma
annotate pkg/imports/isr.go @ 5413:99f32f0dc70c marking-single-beam
Added tools to classify vertices by their heights with class breaks.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 07 Jul 2021 11:42:25 +0200 |
parents | 34bc6041e61e |
children | c9da747d4109 |
rev | line source |
---|---|
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package imports |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "context" |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "time" |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
4256
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4220
diff
changeset
|
21 "gemma.intevation.de/gemma/pkg/common" |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4768
diff
changeset
|
22 "gemma.intevation.de/gemma/pkg/mesh" |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 ) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4827
diff
changeset
|
25 // IsoRefresh is an import job to refresh the pre-calculated |
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4827
diff
changeset
|
26 // iso morphology data when the class breaks were changed. |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 type IsoRefresh struct { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ClassBreaks string `json:"class-breaks"` |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 // ISRJobKind is the unique name of this import job type. |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 const ISRJobKind JobKind = "isr" |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 func init() { RegisterJobCreator(ISRJobKind, isrJobCreator{}) } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 type isrJobCreator struct{} |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 func (isrJobCreator) Description() string { return "refresh iso lines" } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 func (isrJobCreator) AutoAccept() bool { return true } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 func (isrJobCreator) Create() Job { return new(IsoRefresh) } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
5035
56c589f7435d
Enhance comments on implementations of StageDone()
Tom Gottfried <tom@intevation.de>
parents:
5034
diff
changeset
|
44 // StageDone is a NOP for IsoRefresh imports. |
5034
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4852
diff
changeset
|
45 func (isrJobCreator) StageDone(context.Context, *sql.Tx, int64, Feedback) error { |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 return nil |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 func (isrJobCreator) Depends() [2][]string { |
4571
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
50 return srJobCreator{}.Depends() |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 const ( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 fetchSoundingResultsIDsSQL = ` |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 SELECT bottleneck_id, id |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 FROM waterway.sounding_results |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 ORDER BY bottleneck_id |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 ` |
4571
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
59 deleteIsoAreasSQL = ` |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
60 DELETE FROM waterway.sounding_results_iso_areas |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
61 WHERE sounding_result_id = $1 |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
62 ` |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 ) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
4852
046a07a33b19
Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4827
diff
changeset
|
65 // CleanUp of a iso refresh import is a NOP. |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 func (isr *IsoRefresh) CleanUp() error { return nil } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 type bottleneckSoundingResults struct { |
4215
e453d3bf7663
Refresh iso contours import: Fixed usage of SQL to list all bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
69 bn string |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 srs []int64 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 func fetchBottleneckResults( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 ctx context.Context, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 conn *sql.Conn, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 ) ([]bottleneckSoundingResults, error) { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 rows, err := conn.QueryContext(ctx, fetchSoundingResultsIDsSQL) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 if err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 return nil, err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 defer rows.Close() |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 var ids []bottleneckSoundingResults |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 for rows.Next() { |
4215
e453d3bf7663
Refresh iso contours import: Fixed usage of SQL to list all bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
87 var bn string |
e453d3bf7663
Refresh iso contours import: Fixed usage of SQL to list all bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
88 var sr int64 |
e453d3bf7663
Refresh iso contours import: Fixed usage of SQL to list all bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
89 if err := rows.Scan(&bn, &sr); err != nil { |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 return nil, err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 if len(ids) > 0 { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 if ids[len(ids)-1].bn != bn { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 ids = append(ids, bottleneckSoundingResults{ |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 bn: bn, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 srs: []int64{sr}, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 }) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } else { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 ids[len(ids)-1].srs = append(ids[len(ids)-1].srs, sr) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 } else { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 ids = []bottleneckSoundingResults{ |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 {bn: bn, srs: []int64{sr}}, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 if err := rows.Err(); err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 return nil, err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 return ids, nil |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
4767
f66e5b2fa894
Wording: Speak of iso areas instead of iso lines when refreshing the sounding results after a configuration change.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4669
diff
changeset
|
113 // Do executes the actual refreshing of the iso areas. |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 func (isr *IsoRefresh) Do( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 ctx context.Context, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 importID int64, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 conn *sql.Conn, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 feedback Feedback, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 ) (interface{}, error) { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 start := time.Now() |
4767
f66e5b2fa894
Wording: Speak of iso areas instead of iso lines when refreshing the sounding results after a configuration change.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4669
diff
changeset
|
122 feedback.Info("Regenerating iso areas for sounding results " + |
4255
d69a3b19a1ae
Indicate to the user what triggered the import
Tom Gottfried <tom@intevation.de>
parents:
4220
diff
changeset
|
123 "after configuration change") |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 defer func() { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 feedback.Info( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 "Processing all sounding results took %v.", |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 time.Since(start)) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 }() |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4768
diff
changeset
|
130 heights, err := mesh.ParseClassBreaks(isr.ClassBreaks) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 if err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 return nil, err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 bns, err := fetchBottleneckResults(ctx, conn) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 if err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 return nil, err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 for i := range bns { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 start := time.Now() |
4216
cbc75527916f
Refresh iso contour lines import: Improved logging a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4215
diff
changeset
|
142 feedback.Info("Processing bottleneck '%s' ...", bns[i].bn) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 err := isr.processBottleneck( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 ctx, conn, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 heights, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 &bns[i], |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 ) |
4216
cbc75527916f
Refresh iso contour lines import: Improved logging a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4215
diff
changeset
|
148 feedback.Info("Processing took %v.", time.Since(start)) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 if err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 return nil, err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 return nil, nil |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 func (isr *IsoRefresh) processBottleneck( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 ctx context.Context, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 conn *sql.Conn, |
5412
34bc6041e61e
Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5035
diff
changeset
|
160 heights mesh.ClassBreaks, |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 bn *bottleneckSoundingResults, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 ) error { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 // Do one transaction per bottleneck. |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 tx, err := conn.BeginTx(ctx, nil) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 if err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 return nil |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 defer tx.Rollback() |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 |
4571
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
170 insertAreasStmt, err := tx.Prepare(insertIsoAreasSQL) |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
171 if err != nil { |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
172 return err |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
173 } |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
174 defer insertAreasStmt.Close() |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 // For all sounding results in bottleneck. |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 for _, sr := range bn.srs { |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4768
diff
changeset
|
178 tree, err := mesh.FetchMeshDirectly(ctx, tx, sr) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 if err != nil { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 return err |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
5412
34bc6041e61e
Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5035
diff
changeset
|
182 hs := heights.ExtrapolateClassBreaks(tree.Min().Z, tree.Max().Z) |
4256
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4220
diff
changeset
|
183 hs = common.DedupFloat64s(hs) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
4571
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
185 // Delete the old iso areas. |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
186 if _, err := tx.ExecContext(ctx, deleteIsoAreasSQL, sr); err != nil { |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
187 return err |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
188 } |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
189 |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
190 // Calculate and store the iso areas. |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4768
diff
changeset
|
191 box := mesh.Box2D{ |
4768
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
192 X1: tree.Min().X, |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
193 Y1: tree.Min().Y, |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
194 X2: tree.Max().X, |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
195 Y2: tree.Max().Y, |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
196 } |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
197 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4768
diff
changeset
|
198 raster := mesh.NewRaster(box, isoCellSize) |
4768
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
199 raster.Rasterize(tree.Value) |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
200 areas := raster.Trace(hs) |
a2f16bbcc846
Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4767
diff
changeset
|
201 |
4571
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
202 for i, a := range areas { |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
203 if len(a) == 0 { |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
204 continue |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
205 } |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
206 if _, err := insertAreasStmt.ExecContext( |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
207 ctx, |
4669
65845c6522fb
Fixed EPSG call in iso regeneration import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
208 sr, hs[i], tree.EPSG(), |
4571
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
209 a.AsWKB(), |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
210 contourTolerance, |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
211 ); err != nil { |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
212 return err |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
213 } |
a413b4a89bcc
Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4257
diff
changeset
|
214 } |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 |
4220
d8b736ba3f32
Refresh iso contour lines import: Commit the changes!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4216
diff
changeset
|
217 return tx.Commit() |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 } |