annotate pkg/imports/isr.go @ 4768:a2f16bbcc846 direct-diff

Morph differences: Directly raster A and subtract B as a raster.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Oct 2019 02:01:56 +0200
parents f66e5b2fa894
children f4abfd0ee8ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
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
22 "gemma.intevation.de/gemma/pkg/octree"
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
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
25 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
26 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
27 }
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
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 // 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
30 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
31
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 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
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 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
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 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
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) 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
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) 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
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) StageDone(context.Context, *sql.Tx, int64) 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
43 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
44 }
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
45
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 func (isrJobCreator) Depends() [2][]string {
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
47 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
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
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
50 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
51 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
52 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
53 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
54 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
55 `
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
56 deleteIsoAreasSQL = `
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
57 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
58 WHERE sounding_result_id = $1
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
59 `
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
60 )
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
61
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
62 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
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 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
65 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
66 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
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
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
69 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
70 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
71 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
72 ) ([]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
73
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 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
75 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
76 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
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 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
79
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 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
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 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
83 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
84 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
85 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
86 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
87 }
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
88 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
89 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
90 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
91 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
92 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
93 })
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 } 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
95 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
96 }
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 } 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
98 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
99 {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
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 }
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 }
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 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
104 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
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 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
107 }
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
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
109 // 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
110 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
111 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
112 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
113 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
114 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
115 ) (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
116
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 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
118 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
119 "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
120 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
121 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
122 "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
123 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
124 }()
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
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 heights, err := octree.ParseClassBreaks(isr.ClassBreaks)
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 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
128 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
129 }
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
130
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 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
132 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
133 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
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
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 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
137 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
138 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
139 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
140 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
141 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
142 &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
143 )
4216
cbc75527916f Refresh iso contour lines import: Improved logging a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4215
diff changeset
144 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
145 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
146 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
147 }
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
148 }
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
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, 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
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 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
154 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
155 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
156 heights []float64,
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 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
158 ) 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
159 // 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
160 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
161 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
162 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
163 }
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 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
165
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
166 insertAreasStmt, err := tx.Prepare(insertIsoAreasSQL)
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
167 if err != nil {
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
168 return err
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
169 }
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
170 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
171
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
172 // 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
173 for _, sr := range bn.srs {
4658
4bbfe3dd2ab5 Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
174 tree, err := octree.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
175 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
176 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
177 }
4658
4bbfe3dd2ab5 Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
178 hs := octree.ExtrapolateClassBreaks(heights, 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
179 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
180
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
181 // Delete the old iso areas.
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
182 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
183 return err
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
184 }
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
185
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
186 // Calculate and store the iso areas.
4768
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
187 box := octree.Box2D{
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
188 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
189 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
190 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
191 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
192 }
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
193
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
194 raster := octree.NewRaster(box, isoCellSize)
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
195 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
196 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
197
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
198 for i, a := range areas {
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
199 if len(a) == 0 {
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
200 continue
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
201 }
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
202 if _, err := insertAreasStmt.ExecContext(
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
203 ctx,
4669
65845c6522fb Fixed EPSG call in iso regeneration import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4658
diff changeset
204 sr, hs[i], tree.EPSG(),
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
205 a.AsWKB(),
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
206 contourTolerance,
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
207 ); err != nil {
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
208 return err
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
209 }
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
210 }
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
211 }
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
212
4220
d8b736ba3f32 Refresh iso contour lines import: Commit the changes!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4216
diff changeset
213 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
214 }