annotate pkg/imports/isr.go @ 5421:c9da747d4109 marking-single-beam

Extended ISR import job to handle marking scans as well.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 08 Jul 2021 01:46:03 +0200
parents 34bc6041e61e
children b8d5f1cd15fb
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"
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
19 "log"
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
20 "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
21
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"
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
23 "gemma.intevation.de/gemma/pkg/models"
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
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
4852
046a07a33b19 Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
26 // 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
27 // 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
28 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
29 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
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
49564382ffff Added a import queue job 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 // 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
33 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
34
49564382ffff Added a import queue job 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 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
36
49564382ffff Added a import queue job 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 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
38
49564382ffff Added a import queue job 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 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
40
49564382ffff Added a import queue job 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 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
42
49564382ffff Added a import queue job 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 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
44
5035
56c589f7435d Enhance comments on implementations of StageDone()
Tom Gottfried <tom@intevation.de>
parents: 5034
diff changeset
45 // 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
46 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
47 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
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 func (isrJobCreator) Depends() [2][]string {
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
51 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
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
49564382ffff Added a import queue job 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 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
55 fetchSoundingResultsIDsSQL = `
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
56 SELECT
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
57 bottleneck_id,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
58 id,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
59 surtyp
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 FROM waterway.sounding_results
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
61 ORDER BY bottleneck_id`
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
62
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
63 deleteIsoAreasSQL = `
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
64 DELETE FROM waterway.sounding_results_iso_areas
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
65 WHERE sounding_result_id = $1`
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
66
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
67 fetchMarkingPointsSQL = `
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
68 SELECT ST_AsBinary(ST_Transform(points, 4326))
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
69 FROM waterway.sounding_results_marking_points
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
70 WHERE sounding_result_id = $1`
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
71
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
72 deleteMarkingPointsSQL = `
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
73 DELETE FROM waterway.sounding_results_marking_points
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
74 WHERE sounding_result_id = $1`
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
75 )
49564382ffff Added a import queue job 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
4852
046a07a33b19 Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
77 // 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
78 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
79
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
80 type (
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
81 scanResult struct {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
82 id int64
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
83 surveyType models.SurveyType
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
84 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
85 bottleneckSoundingResults struct {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
86 bn string
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
87 srs []scanResult
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
88 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
89 )
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
49564382ffff Added a import queue job 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 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
92 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
93 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
94 ) ([]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
95
49564382ffff Added a import queue job 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 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
97 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
98 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
99 }
49564382ffff Added a import queue job 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 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
101
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
102 var bsrs []bottleneckSoundingResults
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
103
49564382ffff Added a import queue job 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 for rows.Next() {
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
105 var (
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
106 bn string
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
107 id int64
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
108 st string
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
109 )
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
110 if err := rows.Scan(&bn, &id, &st); 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
111 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
112 }
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
113 sr := scanResult{id: id, surveyType: models.SurveyType(st)}
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
114
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
115 if l := len(bsrs); l == 0 || bsrs[l-1].bn != bn {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
116 bsrs = append(bsrs, bottleneckSoundingResults{
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
117 bn: bn,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
118 srs: []scanResult{sr},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
119 })
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 } else {
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
121 bsrs[l-1].srs = append(bsrs[l-1].srs, 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
122 }
49564382ffff Added a import queue job 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 }
49564382ffff Added a import queue job 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 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
125 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
126 }
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
127 return bsrs, 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
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
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
130 // 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
131 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
132 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
133 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
134 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
135 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
136 ) (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
137
49564382ffff Added a import queue job 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 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
139 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
140 "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
141 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
142 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
143 "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
144 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
145 }()
49564382ffff Added a import queue job 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
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
147 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
148 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
149 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
150 }
49564382ffff Added a import queue job 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 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
153 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
154 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
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 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
158 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
159 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
160 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
161 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
162 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
163 &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
164 )
4216
cbc75527916f Refresh iso contour lines import: Improved logging a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4215
diff changeset
165 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
166 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
167 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
168 }
49564382ffff Added a import queue job 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 }
49564382ffff Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170
49564382ffff Added a import queue job 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 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
172 }
49564382ffff Added a import queue job 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
49564382ffff Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 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
175 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
176 conn *sql.Conn,
5412
34bc6041e61e Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
177 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
178 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
179 ) 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
180 // 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
181 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
182 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
183 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
184 }
49564382ffff Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 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
186
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
187 var (
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
188 insertAreasStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
189 deleteAreasStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
190 fetchMarkingPointsStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
191 deleteMarkingPointsStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
192 insertMarkingPointsStmt *sql.Stmt
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
193 )
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
194
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
195 for _, x := range []struct {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
196 stmt **sql.Stmt
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
197 query string
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
198 }{
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
199 {&insertAreasStmt, insertIsoAreasSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
200 {&deleteAreasStmt, deleteIsoAreasSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
201 {&fetchMarkingPointsStmt, fetchMarkingPointsSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
202 {&deleteMarkingPointsStmt, deleteMarkingPointsSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
203 {&insertMarkingPointsStmt, insertMarkingPointsSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
204 } {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
205 if *x.stmt, err = tx.PrepareContext(ctx, x.query); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
206 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
207 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
208 defer (*x.stmt).Close()
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
209 }
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
210
49564382ffff Added a import queue job 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 // 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
212 for _, sr := range bn.srs {
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
213 switch sr.surveyType {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
214 case models.SurveyTypeMarking:
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
215
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
216 // Read all points back in.
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
217
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
218 var points mesh.MultiPointZ
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
219
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
220 if err := func() error {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
221 rows, err := fetchMarkingPointsStmt.QueryContext(ctx, sr.id)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
222 if err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
223 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
224 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
225 defer rows.Close()
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
226
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
227 for rows.Next() {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
228 var buf []byte
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
229 if err := rows.Scan(&buf); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
230 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
231 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
232 var npoints mesh.MultiPointZ
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
233 if err := npoints.FromWKB(buf); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
234 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
235 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
236 points = append(points, npoints...)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
237 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
238 return rows.Err()
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
239 }(); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
240 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
241 }
4768
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
242
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
243 // Delete old points
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
244 if _, err := deleteMarkingPointsStmt.ExecContext(ctx, sr.id); err != nil {
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
245 return err
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
246 }
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
247
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
248 // Re-classify points.
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
249 classes := heights.Classify(points.All())
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
250
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
251 // Should not happen ... Z values over the top.
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
252 if n := len(classes) - 1; n > 1 && len(classes[n]) > 0 {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
253 // Place the over the top values to the class below.
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
254 classes[n-1] = append(classes[n-1], classes[n]...)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
255 classes[n] = nil
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
256 classes = classes[:n]
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
257 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
258
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
259 // Re-insert points
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
260 for i, class := range classes {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
261 // Ignore empty classes
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
262 if len(class) == 0 {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
263 continue
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
264 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
265 if _, err := insertMarkingPointsStmt.ExecContext(
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
266 ctx, sr.id, heights[i], 4326, class.AsWKB(),
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
267 ); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
268 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
269 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
270 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
271
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
272 case models.SurveyTypeMultiBeam, models.SurveyTypeSingleBeam:
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
273 tree, err := mesh.FetchMeshDirectly(ctx, tx, sr.id)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
274 if err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
275 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
276 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
277 hs := heights.ExtrapolateClassBreaks(tree.Min().Z, tree.Max().Z).Dedup()
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
278
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
279 // Delete the old iso areas.
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
280 if _, err := deleteAreasStmt.ExecContext(ctx, sr); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
281 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
282 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
283
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
284 // Calculate and store the iso areas.
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
285 box := mesh.Box2D{
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
286 X1: tree.Min().X,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
287 Y1: tree.Min().Y,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
288 X2: tree.Max().X,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
289 Y2: tree.Max().Y,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
290 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
291
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
292 raster := mesh.NewRaster(box, isoCellSize)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
293 raster.Rasterize(tree.Value)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
294 areas := raster.Trace(hs)
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
295
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
296 for i, a := range areas {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
297 if len(a) == 0 {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
298 continue
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
299 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
300 if _, err := insertAreasStmt.ExecContext(
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
301 ctx,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
302 sr, hs[i], tree.EPSG(),
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
303 a.AsWKB(),
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
304 contourTolerance,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
305 ); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
306 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
307 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
308 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
309 default:
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
310 log.Printf("error: unknown survey type '%s'\n", sr.surveyType)
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
311 }
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
312 }
49564382ffff Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313
4220
d8b736ba3f32 Refresh iso contour lines import: Commit the changes!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4216
diff changeset
314 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
315 }