annotate pkg/imports/isr.go @ 5428:b8d5f1cd15fb marking-single-beam

Simplified classification. Needs testing.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 11 Jul 2021 13:08:49 +0200
parents c9da747d4109
children fc79622783a7
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 }
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
151 heights = heights.Dedup()
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
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 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
154 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
155 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
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
49564382ffff Added a import queue job 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 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
159 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
160 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
161 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
162 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
163 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
164 &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
165 )
4216
cbc75527916f Refresh iso contour lines import: Improved logging a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4215
diff changeset
166 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
167 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
168 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
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
49564382ffff Added a import queue job 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 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
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
49564382ffff Added a import queue job 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 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
176 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
177 conn *sql.Conn,
5412
34bc6041e61e Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
178 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
179 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
180 ) 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
181 // 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
182 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
183 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
184 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
185 }
49564382ffff Added a import queue job 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 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
187
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
188 var (
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
189 insertAreasStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
190 deleteAreasStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
191 fetchMarkingPointsStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
192 deleteMarkingPointsStmt,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
193 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
194 )
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
195
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
196 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
197 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
198 query string
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
199 }{
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
200 {&insertAreasStmt, insertIsoAreasSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
201 {&deleteAreasStmt, deleteIsoAreasSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
202 {&fetchMarkingPointsStmt, fetchMarkingPointsSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
203 {&deleteMarkingPointsStmt, deleteMarkingPointsSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
204 {&insertMarkingPointsStmt, insertMarkingPointsSQL},
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
205 } {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
206 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
207 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
208 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
209 defer (*x.stmt).Close()
4571
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 // 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
213 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
214 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
215 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
216
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
217 // 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
218
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
219 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
220
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
221 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
222 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
223 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
224 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
225 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
226 defer rows.Close()
4571
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
227
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
228 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
229 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
230 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
231 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
232 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
233 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
234 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
235 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
236 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
237 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
238 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
239 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
240 }(); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
241 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
242 }
4768
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4767
diff changeset
243
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
244 // 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
245 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
246 return err
a413b4a89bcc Update areas if config has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4257
diff changeset
247 }
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
248
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
249 // Re-classify points.
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
250 classes := heights.Classify(points)
5421
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
251
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
252 // 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
253 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
254 // 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
255 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
256 continue
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 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
259 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
260 ); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
261 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
262 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
263 }
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 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
266 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
267 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
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 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
271
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
272 // 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
273 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
274 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
275 }
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 // 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
278 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
279 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
280 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
281 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
282 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
283 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
284
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
285 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
286 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
287 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
288
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
289 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
290 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
291 continue
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
292 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
293 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
294 ctx,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
295 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
296 a.AsWKB(),
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
297 contourTolerance,
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
298 ); err != nil {
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
299 return err
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
300 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
301 }
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
302 default:
c9da747d4109 Extended ISR import job to handle marking scans as well.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
303 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
304 }
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
305 }
49564382ffff Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306
4220
d8b736ba3f32 Refresh iso contour lines import: Commit the changes!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4216
diff changeset
307 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
308 }