annotate pkg/imports/sr.go @ 5679:03dfbe675842 sr-v2

Simplified version handling.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 11 Feb 2024 12:37:09 +0100
parents 4abbb62d2bed
children 148abae1fcd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1017
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
2 // without warranty, see README.md and license for details.
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
3 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
6 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
7 // Copyright (C) 2018 by via donau
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
9 // Software engineering by Intevation GmbH
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
10 //
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
11 // Author(s):
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
1337
53057ab27ff2 add headers for licensing to some middleware files
Fadi Abbud <fadi.abbud@intevation.de>
parents: 1292
diff changeset
13 // * Tom Gottfried <tom@intevation.de>
1017
a244b18cb916 Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 991
diff changeset
14
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 package imports
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import (
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 "archive/zip"
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 "bufio"
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "context"
973
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 972
diff changeset
21 "crypto/sha1"
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 "database/sql"
973
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 972
diff changeset
23 "encoding/hex"
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 "errors"
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 "fmt"
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 "io"
1184
064d44ccc6f2 Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents: 1168
diff changeset
27 "math"
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 "os"
960
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
29 "path"
978
544a5cfe07cd Started with endpoint for uploading sounding result and trigger respective import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 977
diff changeset
30 "path/filepath"
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
31 "regexp"
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 "strconv"
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 "strings"
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
34 "sync"
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 "time"
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
960
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
37 shp "github.com/jonas-p/go-shp"
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
38
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
39 "gemma.intevation.de/gemma/pkg/common"
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
40 "gemma.intevation.de/gemma/pkg/log"
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
41 "gemma.intevation.de/gemma/pkg/mesh"
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
42 "gemma.intevation.de/gemma/pkg/models"
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
43 "gemma.intevation.de/gemma/pkg/wkb"
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 )
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
1498
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
46 // SoundingResult is a Job to import sounding reults
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
47 // from a ZIP file into the database.
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
48 type SoundingResult struct {
1498
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
49 // Dir is the folder in the file system where the
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
50 // 'sr.zip' is expect to be.
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
51 Dir string `json:"dir"`
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
52
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
53 // Override data
1498
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
54 // Date if given overrides the date value from the meta.json.
1900
6a67cd819e93 To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1786
diff changeset
55 Date *models.Date `json:"date,omitempty"`
1498
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
56 // Date if given overrides the name of the bottleneck from the meta.json.
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
57 Bottleneck *string `json:"bottleneck,omitempty"`
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
58 // EPSG if given overrides the EPSG code from the meta.json.
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
59 // Defaults to WGS84.
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
60 EPSG *uint `json:"epsg,omitempty"`
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
61 // DepthReference if given overides the DepthReference value
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
62 // from the meta.json.
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
63 DepthReference *string `json:"depth-reference,omitempty"`
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
64 // SingleBeam is kept in for compat.
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
65 SingleBeam *bool `json:"single-beam,omitempty"`
5403
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5315
diff changeset
66 // SurveyType indicates that the sounding is a single beam scan.
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5315
diff changeset
67 SurveyType *models.SurveyType `json:"survey-type,omitempty"`
3945
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
68 // NegateZ indicated that the Z values of thy XYZ input should be
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
69 // multiplied by -1.
3946
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
70 NegateZ *bool `json:"negate-z,omitempty"`
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
71 }
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
964
1e2dce348cfb Serialize boundary polygon of sounding result as WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 961
diff changeset
73 const (
1130
42617bba8709 Go from 50cm to 10cm stepwidth in calculating the contorlines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
74 contourStepWidth = 0.1
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
75 contourTolerance = 0.1
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
76 )
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
77
3646
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
78 const (
4751
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
79 // multiBeamThreshold is the number of points m² which
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
80 // is assumed that greater values are indicators for
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
81 // an already interpolated point cloud.
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
82 multiBeamThreshold = 1.0 / 5.0
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
83 )
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
84
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
85 const (
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
86 // pointsPerSquareMeter is the average number of points
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
87 // when generating a artifical height model for single beam scans.
4754
64979fec89a7 SR import: Reduce the point density in interpolation 1 point per meter².
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4751
diff changeset
88 pointsPerSquareMeter = 1.0
3646
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
89 )
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
90
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
91 const (
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
92 // isoCellSize is the side length of a raster cell when tracing
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
93 // iso areas.
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
94 isoCellSize = 0.5
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
95 )
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
96
4182
49012340336c Made 'golint' finally happy with imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
97 // SRJobKind is the unique name of this import job type.
991
a301d240905f Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
98 const SRJobKind JobKind = "sr"
a301d240905f Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
99
1136
a5069da2f0b7 Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1131
diff changeset
100 type srJobCreator struct{}
a5069da2f0b7 Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1131
diff changeset
101
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: 4182
diff changeset
102 func init() { RegisterJobCreator(SRJobKind, srJobCreator{}) }
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
103
1754
807569b08513 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1664
diff changeset
104 func (srJobCreator) Description() string { return "sounding results" }
807569b08513 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1664
diff changeset
105
807569b08513 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1664
diff changeset
106 func (srJobCreator) AutoAccept() bool { return false }
1646
a0982c38eac0 Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1572
diff changeset
107
2187
7c83b5277c1c Import queue: Removed boilerplate code to deserialize jobs from JSON by making it part of the import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2168
diff changeset
108 func (srJobCreator) Create() Job { return new(SoundingResult) }
1136
a5069da2f0b7 Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1131
diff changeset
109
5564
aaa9e658cabd Log export: Added marker interface to JobCreators that log messages should be loaded at export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5562
diff changeset
110 // LoadingLogs ensures that log lines are loaded when import is exported.
aaa9e658cabd Log export: Added marker interface to JobCreators that log messages should be loaded at export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5562
diff changeset
111 func (srJobCreator) LoadingLogs() bool { return true }
aaa9e658cabd Log export: Added marker interface to JobCreators that log messages should be loaded at export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5562
diff changeset
112
3219
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2963
diff changeset
113 func (srJobCreator) Depends() [2][]string {
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2963
diff changeset
114 return [2][]string{
5410
8b6018ed3ffd If doing SR imports, lock sounding_results_marking_points table, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5407
diff changeset
115 {"sounding_results", "sounding_results_iso_areas",
8b6018ed3ffd If doing SR imports, lock sounding_results_marking_points table, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5407
diff changeset
116 "sounding_results_marking_points"},
3219
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2963
diff changeset
117 {"bottlenecks"},
1136
a5069da2f0b7 Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1131
diff changeset
118 }
a5069da2f0b7 Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1131
diff changeset
119 }
a5069da2f0b7 Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1131
diff changeset
120
5035
56c589f7435d Enhance comments on implementations of StageDone()
Tom Gottfried <tom@intevation.de>
parents: 5034
diff changeset
121 // StageDone moves the imported sounding result out of the staging area.
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
122 func (srJobCreator) StageDone(
1328
d753ce6cf588 To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1317
diff changeset
123 ctx context.Context,
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
124 tx *sql.Tx,
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
125 id int64,
5034
59a99655f34d Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4852
diff changeset
126 _ Feedback,
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
127 ) error {
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
128 _, err := tx.ExecContext(ctx, srStageDoneSQL, id)
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
129 return err
991
a301d240905f Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
130 }
a301d240905f Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 988
diff changeset
131
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
132 const (
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
133 srStageDoneSQL = `
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
134 UPDATE waterway.sounding_results SET staging_done = true
1502
0abcc82ef976 Sounding results: Be a bit more precise when setting stageing_done.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1501
diff changeset
135 WHERE id = (
1995
59055c8301df Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents: 1900
diff changeset
136 SELECT key from import.track_imports
1502
0abcc82ef976 Sounding results: Be a bit more precise when setting stageing_done.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1501
diff changeset
137 WHERE import_id = $1 AND
0abcc82ef976 Sounding results: Be a bit more precise when setting stageing_done.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1501
diff changeset
138 relation = 'waterway.sounding_results'::regclass)`
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1184
diff changeset
139
2529
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
140 insertHullSQL = `
961
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
141 INSERT INTO waterway.sounding_results (
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
142 bottleneck_id,
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
143 date_info,
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
144 depth_reference,
4629
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
145 area,
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
146 surtyp,
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
147 zpg_exception
5585
7e8830c808ba Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents: 5564
diff changeset
148 ) VALUES (
7e8830c808ba Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents: 5564
diff changeset
149 $1,
961
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
150 $2::date,
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
151 $3,
2529
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
152 (SELECT
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
153 CASE WHEN $5::bytea IS NULL THEN
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
154 ST_Transform(ST_ConcaveHull(ST_Force2D(ST_GeomFromWKB($4, $6::integer)), 0.7), 4326)::geography
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
155 ELSE
3652
f415c5ed60f6 Another attempt to fix the ST_IsValid check contstraint problem ... and also failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3651
diff changeset
156 ST_MakeValid(ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326))::geography
4629
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
157 END),
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
158 $7,
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
159 $8
5585
7e8830c808ba Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents: 5564
diff changeset
160 )
971
f9fb6c399f3f Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 964
diff changeset
161 RETURNING
f9fb6c399f3f Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 964
diff changeset
162 id,
2529
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
163 ST_X(ST_Centroid(area::geometry)),
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
164 ST_Y(ST_Centroid(area::geometry)),
2833
1b6840093eac Prevent calculation of wrong UTM zones
Tom Gottfried <tom@intevation.de>
parents: 2612
diff changeset
165 best_utm(area),
1b6840093eac Prevent calculation of wrong UTM zones
Tom Gottfried <tom@intevation.de>
parents: 2612
diff changeset
166 ST_AsBinary(ST_Transform(area::geometry, best_utm(area)))
2529
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
167 `
973
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 972
diff changeset
168
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
169 reprojectPointsBufferedSQL = `
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
170 SELECT
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
171 ST_AsBinary(ST_Transform(ST_GeomFromWKB($1, $2::integer), $3::integer)),
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
172 ST_AsBinary(ST_Buffer(ST_Transform(ST_GeomFromWKB($1, $2::integer), $3::integer), 0.1)),
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
173 ST_Area(ST_Transform(ST_GeomFromWKB($1, $2::integer), $3::integer))`
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
174
4660
6eab3ac0e849 Speak of meshes instead od octrees as they are not longer used.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4654
diff changeset
175 insertMeshSQL = `
1131
2e6b47cdb2ca Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents: 1130
diff changeset
176 UPDATE waterway.sounding_results SET
5678
4abbb62d2bed Write mesh version to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5595
diff changeset
177 mesh_checksum = $2, mesh_index = $3, mesh_index_version = $4
1131
2e6b47cdb2ca Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents: 1130
diff changeset
178 WHERE id = $1`
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
179
3651
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
180 repairBoundarySQL = `
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
181 SELECT
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
182 ST_AsBinary(ST_Buffer(ST_MakeValid(ST_GeomFromWKB($1, $2::integer)), 0.0)),
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
183 ST_AsBinary(ST_Buffer(ST_MakeValid(ST_GeomFromWKB($1, $2::integer)), 0.1))`
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
184
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
185 insertIsoAreasSQL = `
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
186 INSERT INTO waterway.sounding_results_iso_areas (
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
187 sounding_result_id,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
188 height,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
189 areas
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
190 )
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
191 SELECT
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
192 $1,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
193 $2,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
194 ST_Transform(
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
195 ST_Multi(
4734
56bd9ba0354c Removed ST_MakeValid() call from storing iso areas in SR import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4686
diff changeset
196 ST_Collectionextract(
56bd9ba0354c Removed ST_MakeValid() call from storing iso areas in SR import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4686
diff changeset
197 ST_SimplifyPreserveTopology(ST_GeomFromWKB($4, $3::integer), $5),
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
198 3
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
199 )
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
200 ),
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
201 4326
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
202 )
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
203 FROM waterway.sounding_results sr
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
204 WHERE id = $1
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
205 `
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
206 insertMarkingPointsSQL = `
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
207 INSERT INTO waterway.sounding_results_marking_points (
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
208 sounding_result_id,
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
209 height,
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
210 points
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
211 )
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
212 SELECT
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
213 $1,
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
214 $2,
5417
2d294ad81241 Dont loose Z values in markings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5416
diff changeset
215 ST_Transform(ST_GeomFromWKB($4, $3::integer), 4326)
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
216 FROM waterway.sounding_results sr
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
217 WHERE id = $1
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
218 `
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
219
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
220 selectGaugeLDCSQL = `
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
221 SELECT
3518
4cd4375efd5d ZP for sounding result imports: Use precise name of the depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3504
diff changeset
222 grwl.value,
4cd4375efd5d ZP for sounding result imports: Use precise name of the depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3504
diff changeset
223 grwl.depth_reference
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
224 FROM waterway.gauges_reference_water_levels grwl
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
225 JOIN waterway.bottlenecks bns
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
226 ON grwl.location = bns.gauge_location
4055
98e2041c7ebf Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents: 3977
diff changeset
227 AND grwl.validity @> CAST($2 AS timestamptz)
5585
7e8830c808ba Fixed SR import for use of Bottleneck_Id instead of bottlenecks objnam.
Sascha Wilde <wilde@sha-bang.de>
parents: 5564
diff changeset
228 WHERE bns.bottleneck_id = $1
3645
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
229 AND bns.validity @> CAST($2 AS timestamptz)
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
230 AND grwl.depth_reference like 'LDC%'
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
231 `
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
232
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
233 selectZPGExceptionAllowedSQL = `
5314
0e8fd0e5bf36 Sysadmins are also granted the ZPG exception if they are importing sounding data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5305
diff changeset
234 SELECT rolname = 'sys_admin' OR country IN ('BG', 'RO')
0e8fd0e5bf36 Sysadmins are also granted the ZPG exception if they are importing sounding data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5305
diff changeset
235 FROM users.list_users WHERE username = current_user`
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
236
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
237 reprojectPointsSingleBeamSQL = `
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
238 SELECT
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
239 ST_AsBinary(
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
240 ST_Transform(
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
241 ST_GeomFromWKB($1, $2::integer),
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
242 best_utm(CAST(ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS geography)))),
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
243 best_utm(CAST(ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS geography))
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
244 `
961
a4c92e0ef2e1 Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 960
diff changeset
245 )
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
247 var (
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
248 bottleneckRe,
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
249 surveyTypeRe,
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
250 dateRe,
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
251 negateZRe *regexp.Regexp
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
252 recoverRegsOnce sync.Once
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
253 )
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
254
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
255 func compileRecoverRegs() {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
256 bottleneckRe = regexp.MustCompile(`Bottleneck:\s*(.+)\s*$`)
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
257 surveyTypeRe = regexp.MustCompile(`Processing as\s+([^\s]+)\s+beam scan.`)
5561
b91716d2acc6 Fixed log message analyzing in log export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5560
diff changeset
258 dateRe = regexp.MustCompile(`Survey date:\s*(\d{4}-\d{2}-\d{2})`)
b91716d2acc6 Fixed log message analyzing in log export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5560
diff changeset
259 negateZRe = regexp.MustCompile(`Z values will be negated\.`)
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
260 }
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
261
4852
046a07a33b19 Fixed the golint issues of the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
262 // Description gives a short info about relevant facts of this import.
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
263 func (sr *SoundingResult) Description(msgs []string) (string, error) {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
264
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
265 recoverRegsOnce.Do(compileRecoverRegs)
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
266
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
267 //log.Debugln(strings.Join(msgs, "\n") + "\n\n")
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
268
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
269 var (
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
270 bottleneck, st, date string
5562
5152b4db40cc Simplified code of log export a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5561
diff changeset
271 negZ bool
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
272 )
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
273
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
274 for _, msg := range msgs {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
275 if m := bottleneckRe.FindStringSubmatch(msg); m != nil {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
276 bottleneck = m[1]
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
277 continue
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
278 }
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
279 if m := surveyTypeRe.FindStringSubmatch(msg); m != nil {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
280 st = m[1]
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
281 continue
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
282 }
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
283 if m := dateRe.FindStringSubmatch(msg); m != nil {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
284 date = m[1]
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
285 continue
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
286 }
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
287 if negateZRe.MatchString(msg) {
5562
5152b4db40cc Simplified code of log export a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5561
diff changeset
288 negZ = true
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
289 }
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
290 }
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
291
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
292 var descs []string
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
293
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
294 if sr.Bottleneck != nil {
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
295 descs = append(descs, *sr.Bottleneck)
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
296 } else if bottleneck != "" {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
297 log.Debugf("bottleneck recovered: %s\n", bottleneck)
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
298 descs = append(descs, bottleneck)
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
299 }
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
300
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
301 if sr.Date != nil {
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
302 descs = append(descs, (*sr).Date.Format(common.DateFormat))
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
303 } else if date != "" {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
304 log.Debugf("date recovered: %s\n", date)
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
305 descs = append(descs, date)
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
306 }
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
307
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
308 if sr.NegateZ != nil && *sr.NegateZ {
5561
b91716d2acc6 Fixed log message analyzing in log export.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5560
diff changeset
309 descs = append(descs, "negateZ")
5562
5152b4db40cc Simplified code of log export a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5561
diff changeset
310 } else if negZ {
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
311 log.Debugln("negateZ recovered")
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
312 descs = append(descs, "negateZ")
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
313 }
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
314
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
315 if sr.SurveyType != nil {
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
316 descs = append(descs, string(*sr.SurveyType))
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
317 } else if st != "" {
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
318 log.Debugf("survey type recovered: %s\n", st)
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
319 descs = append(descs, st)
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
320 }
5560
f2204f91d286 Join the log lines of imports to the log exports to recover data from them.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5522
diff changeset
321
4791
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
322 return strings.Join(descs, "|"), nil
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
323 }
1fef4679b07a Added an endpoint GET api/imports/export to export imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4776
diff changeset
324
3946
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
325 func (sr *SoundingResult) negateZ() bool {
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
326 return sr.NegateZ != nil && *sr.NegateZ
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
327 }
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
328
1498
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
329 // Do executes the actual sounding result import.
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
330 func (sr *SoundingResult) Do(
1328
d753ce6cf588 To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1317
diff changeset
331 ctx context.Context,
1168
930fdd8b474f Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1138
diff changeset
332 importID int64,
930fdd8b474f Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1138
diff changeset
333 conn *sql.Conn,
930fdd8b474f Track successfull imports in a separate table to be able to remove them later.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1138
diff changeset
334 feedback Feedback,
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
335 ) (interface{}, error) {
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
336
3587
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
337 start := time.Now()
2529
45d51a49f191 SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
338
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
339 zpath := filepath.Join(sr.Dir, "sr.zip")
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
340
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
341 z, err := zip.OpenReader(zpath)
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
342 if err != nil {
3762
98d5dd2f0ca1 Don't show unnecessary warnings when uploading TXT file for SR.
Sascha Wilde <wilde@intevation.de>
parents: 3748
diff changeset
343 feedback.Info("%v", err)
98d5dd2f0ca1 Don't show unnecessary warnings when uploading TXT file for SR.
Sascha Wilde <wilde@intevation.de>
parents: 3748
diff changeset
344 feedback.Info("Falling back to TXT file mode.")
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
345 z = nil
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
346 }
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
347 if z != nil {
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
348 defer z.Close()
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
349 }
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
350
1138
443fc80a315f Don't issue new lines at end of log messages when importing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1137
diff changeset
351 feedback.Info("Looking for 'meta.json'")
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
352
1225
4d7c44f7044e Factored out som zip lookup code to be reusable in sounding result upload controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
353 mf := common.FindInZIP(z, "meta.json")
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
354 if mf == nil && !sr.completeOverride() {
4177
8b75ac5e243e Made 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4171
diff changeset
355 return nil, errors.New("cannot find 'meta.json'")
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
356 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
357
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
358 m, err := sr.loadMeta(mf)
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
359 if err != nil {
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
360 return nil, err
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
361 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
362
2873
b1707f60f241 SR import: Log name of bottleneck and survey date into import log.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2833
diff changeset
363 feedback.Info("Bottleneck: %s", m.Bottleneck)
b1707f60f241 SR import: Log name of bottleneck and survey date into import log.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2833
diff changeset
364 feedback.Info("Survey date: %s", m.Date.Format(common.DateFormat))
b1707f60f241 SR import: Log name of bottleneck and survey date into import log.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2833
diff changeset
365
3487
fdb0439850d5 Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3479
diff changeset
366 var xform vertexTransform
fdb0439850d5 Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3479
diff changeset
367
3946
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
368 if sr.negateZ() {
5522
728b58946c34 SR import: Log if Z values will be negated.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5473
diff changeset
369 feedback.Info("Z values will be negated.")
3945
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
370 xform = negateZTransform
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
371 } else {
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
372 xform = identityTransform
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
373 }
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
374
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
375 var zpgException bool
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
376
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
377 if m.DepthReference == "ZPG" {
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
378 feedback.Info("Found ZPG as reference system -> translating Z values to LDC")
3487
fdb0439850d5 Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3479
diff changeset
379 var ldc float64
3518
4cd4375efd5d ZP for sounding result imports: Use precise name of the depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3504
diff changeset
380 var depthReference string
3645
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
381 err := conn.QueryRowContext(ctx,
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
382 selectGaugeLDCSQL,
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
383 m.Bottleneck,
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
384 m.Date.Time,
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3609
diff changeset
385 ).Scan(
3518
4cd4375efd5d ZP for sounding result imports: Use precise name of the depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3504
diff changeset
386 &ldc,
4cd4375efd5d ZP for sounding result imports: Use precise name of the depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3504
diff changeset
387 &depthReference,
4cd4375efd5d ZP for sounding result imports: Use precise name of the depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3504
diff changeset
388 )
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
389 switch {
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
390 case err == sql.ErrNoRows:
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
391 if err := conn.QueryRowContext(
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
392 ctx, selectZPGExceptionAllowedSQL).Scan(&zpgException); err != nil {
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
393 return nil, err
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
394 }
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
395 if !zpgException {
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
396 return nil, errors.New("cannot load LDC value")
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
397 }
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
398 feedback.Warn("Not LCD found, but ZPG exception granted")
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
399
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
400 case err != nil:
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
401 return nil, err
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
402 }
3904
4b5c4007fc5d SR import: Fixed LDC treatment if depth reference system is ZPG.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3882
diff changeset
403
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
404 if !zpgException {
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
405 // LDC is cm. The data is in m.
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
406 ldc /= 100
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
407 xform = chainTransforms(
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
408 xform,
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
409 func(v mesh.Vertex) mesh.Vertex {
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
410 return mesh.Vertex{X: v.X, Y: v.Y, Z: v.Z + ldc}
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
411 })
5315
12a5e128255f If there is no ZPG exception correct the depth reference system from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5314
diff changeset
412 m.DepthReference = depthReference
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
413 }
3479
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
414 }
83b58f6356e7 Translate sounding results Z values import to LDC if ZPG was found as depth reference system.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3219
diff changeset
415
1328
d753ce6cf588 To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1317
diff changeset
416 if err := m.Validate(ctx, conn); err != nil {
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
417 return nil, common.ToError(err)
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
418 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
419
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
420 var xyz mesh.MultiPointZ
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
421
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
422 if z != nil { // Scanning ZIP file for *.xyz file.
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
423 var xyzf *zip.File
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
424 for _, ext := range []string{".xyz", ".txt"} {
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
425 feedback.Info("Looking for '*%s'", ext)
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
426 if xyzf = common.FindInZIP(z, ext); xyzf != nil {
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
427 break
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
428 }
1528
5874cedd7f91 Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1502
diff changeset
429 }
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
430 if xyzf == nil {
4177
8b75ac5e243e Made 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4171
diff changeset
431 return nil, errors.New("cannot find any *.xyz or *.txt file")
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
432 }
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
433 xyz, err = loadXYZ(xyzf, feedback, xform)
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
434 } else { // TXT file mode
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
435 xyz, err = loadXYZFile(zpath, feedback, xform)
1528
5874cedd7f91 Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1502
diff changeset
436 }
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
437 if err != nil {
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
438 return nil, err
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
439 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
440
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
441 if len(xyz) == 0 {
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
442 return nil, errors.New("XYZ does not contain any vertices")
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
443 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
444
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
445 // Is there a boundary shapefile in the ZIP archive?
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
446 boundary, err := loadBoundary(z)
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
447 if err != nil {
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
448 return nil, err
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
449 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
450
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
451 tx, err := conn.BeginTx(ctx, nil)
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
452 if err != nil {
1392
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1384
diff changeset
453 return nil, err
988
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
454 }
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
455 defer tx.Rollback()
7dfd3db94e6d In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 984
diff changeset
456
4629
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
457 summary, err := sr.processScan(
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
458 ctx,
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
459 tx,
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
460 feedback,
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
461 importID,
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
462 m,
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
463 xyz,
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
464 boundary,
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
465 zpgException,
4629
7acb03e8a737 SR import: Store in sounding_result table if import is single or multi beam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4578
diff changeset
466 )
3587
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
467 if err != nil {
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
468 return nil, err
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
469 }
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
470
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
471 if err = tx.Commit(); err != nil {
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
472 feedback.Error(
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
473 "Storing sounding result failed after %v.", time.Since(start))
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
474 return nil, err
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
475 }
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
476
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
477 feedback.Info(
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
478 "Storing sounding result was successful after %v.", time.Since(start))
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
479
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
480 return summary, nil
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
481 }
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
482
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
483 func (sr *SoundingResult) processScan(
3587
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
484 ctx context.Context,
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
485 tx *sql.Tx,
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
486 feedback Feedback,
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
487 importID int64,
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
488 m *models.SoundingResultMeta,
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
489 xyz mesh.MultiPointZ,
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
490 boundary polygonSlice,
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
491 zpgException bool,
3587
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
492 ) (interface{}, error) {
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
493
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
494 feedback.Info("Processing as %s beam scan.", m.SurveyType)
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
495
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
496 feedback.Info("Reproject XYZ data.")
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
497
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
498 start := time.Now()
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
499
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
500 var reproj []byte
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
501 var epsg uint32
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
502
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
503 if err := tx.QueryRowContext(
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
504 ctx,
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
505 reprojectPointsSingleBeamSQL,
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
506 xyz.AsWKB(),
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
507 m.EPSG,
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
508 ).Scan(&reproj, &epsg); err != nil {
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
509 return nil, err
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
510 }
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
511
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
512 if err := xyz.FromWKB(reproj); err != nil {
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
513 return nil, err
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
514 }
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
515
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
516 feedback.Info("Reprojecting points to EPSG %d took %v.",
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
517 epsg, time.Since(start))
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
518 feedback.Info("Number of reprojected points: %d", len(xyz))
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
519 feedback.Info("Triangulate XYZ data.")
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
520
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
521 start = time.Now()
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
522 tri, err := mesh.Triangulate(xyz)
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
523 if err != nil {
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
524 return nil, err
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
525 }
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
526 feedback.Info("Triangulation took %v.", time.Since(start))
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
527 feedback.Info("Number triangles: %d.", len(tri.Triangles)/3)
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
528
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
529 var (
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
530 clippingPolygon mesh.Polygon
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
531 clippingPolygonBuffered mesh.Polygon
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
532 removed map[int32]struct{}
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
533 polygonArea float64
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
534 clippingPolygonWKB []byte
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
535 )
3646
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
536
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
537 if boundary == nil {
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
538 feedback.Info("No boundary given. Calulate from XYZ data.")
3733
ec86a7155377 Estimated too large triangles as triangles which have an edge which is at least 3.5 times as long as the standard dev of the longest egde per inner triangle.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3664
diff changeset
539 tooLongEdge := tri.EstimateTooLong()
3655
a6c671abbc35 Started with cleaning up the single beam import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3654
diff changeset
540 feedback.Info("Eliminate triangles with edges longer than %.2f meters.", tooLongEdge)
3646
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
541
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
542 var polygon mesh.LineStringZ
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
543 start = time.Now()
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
544 polygon, removed = tri.ConcaveHull(tooLongEdge)
3646
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
545
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
546 polygonArea = polygon.Area()
3646
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
547 if polygonArea < 0.0 { // counter clockwise
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
548 polygonArea = -polygonArea
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
549 polygon.Reverse()
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
550 }
810b28f59b8b Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3609
diff changeset
551
3651
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
552 clippingPolygon.FromLineStringZ(polygon)
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
553
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
554 var buffered []byte
3651
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
555 if err := tx.QueryRowContext(
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
556 ctx,
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
557 repairBoundarySQL,
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
558 clippingPolygon.AsWKB(),
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
559 epsg,
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
560 ).Scan(&clippingPolygonWKB, &buffered); err != nil {
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
561 return nil, err
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
562 }
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
563
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
564 if err := clippingPolygon.FromWKB(clippingPolygonWKB); err != nil {
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
565 return nil, err
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
566 }
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
567 if err := clippingPolygonBuffered.FromWKB(buffered); err != nil {
3651
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
568 return nil, err
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
569 }
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
570
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
571 feedback.Info("Calculating took %v.", time.Since(start))
3600
6590733e2ebc SR import: If in single beam mode and no boundary is given eliminate triangles which have at least an edge with is longer than 98% of the overall edge lengths.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3596
diff changeset
572
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
573 } else { // has Boundary
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
574 feedback.Info("Using uploaded boundary polygon.")
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
575 var buffered []byte
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
576 if err = tx.QueryRowContext(
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
577 ctx,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
578 reprojectPointsBufferedSQL,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
579 boundary.asWKB(),
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
580 m.EPSG,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
581 epsg,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
582 ).Scan(&clippingPolygonWKB, &buffered, &polygonArea); err != nil {
3651
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
583 return nil, err
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
584 }
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
585 if err := clippingPolygon.FromWKB(clippingPolygonWKB); err != nil {
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
586 return nil, err
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
587 }
3651
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
588 if err := clippingPolygonBuffered.FromWKB(buffered); err != nil {
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
589 return nil, err
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
590 }
c368a9a20478 Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3650
diff changeset
591
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
592 tin := tri.Tin()
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
593 tin.EPSG = epsg
3650
01ce3ba9b0d0 Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3646
diff changeset
594
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
595 var str mesh.STRTree
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
596 str.Build(tin)
3655
a6c671abbc35 Started with cleaning up the single beam import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3654
diff changeset
597
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
598 removed = str.Clip(&clippingPolygon)
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
599 }
3650
01ce3ba9b0d0 Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3646
diff changeset
600
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
601 if m.SurveyType == models.SurveyTypeSingleBeam {
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
602
4751
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
603 origDensity := float64(len(xyz)) / polygonArea
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
604
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
605 feedback.Info("Boundary area: %.2fm²", polygonArea)
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
606 feedback.Info("Original point density: %.2f points/m²", origDensity)
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
607
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
608 if origDensity > multiBeamThreshold {
4776
0feddad5bb6d Fixed another formatting oversight.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4768
diff changeset
609 feedback.Warn("The density is greater than %.2f points/m².", multiBeamThreshold)
4751
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
610 feedback.Warn("It is assumed that the data is already interpolated.")
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
611 goto multibeam
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
612 }
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
613
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
614 // Build the first mesh to generate random points on.
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
615
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
616 feedback.Info("Build virtual DEM based on original XYZ data.")
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
617
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
618 start = time.Now()
3650
01ce3ba9b0d0 Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3646
diff changeset
619
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
620 tin := tri.Tin()
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
621 var virtual mesh.STRTree
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
622 virtual.BuildWithout(tin, removed)
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
623
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
624 feedback.Info("Building took %v", time.Since(start))
3650
01ce3ba9b0d0 Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3646
diff changeset
625
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
626 numPoints := int(math.Ceil(polygonArea * pointsPerSquareMeter))
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
627
4763
d786c37b02c0 Fixed a formatting mistake.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4762
diff changeset
628 feedback.Info("Generate %d random points for an average density of ~%.2f points/m².",
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
629 numPoints, pointsPerSquareMeter)
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
630
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
631 start = time.Now()
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
632
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
633 generated := make(mesh.LineStringZ, 0, numPoints+clippingPolygon.NumVertices(0))
3650
01ce3ba9b0d0 Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3646
diff changeset
634
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
635 mesh.GenerateRandomVertices(
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
636 numPoints,
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
637 tin.Min, tin.Max,
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
638 virtual.Value,
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
639 func(vertices []mesh.Vertex) {
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
640 generated = append(generated, vertices...)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
641 })
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
642
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
643 feedback.Info("Generating %d points took %v.", len(generated), time.Since(start))
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
644
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
645 // Add the boundary to new point cloud.
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
646 dupes := map[[2]float64]struct{}{}
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
647 clippingPolygon.Vertices(0, func(x, y float64) {
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
648 key := [2]float64{x, y}
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
649 if _, found := dupes[key]; found {
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
650 return
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
651 }
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
652 dupes[key] = struct{}{}
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
653 if z, ok := virtual.Value(x, y); ok {
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
654 generated = append(generated, mesh.Vertex{X: x, Y: y, Z: z})
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
655 }
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
656 })
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
657
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
658 feedback.Info("Triangulate new point cloud.")
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
659 xyz = mesh.MultiPointZ(generated)
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
660 start = time.Now()
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
661
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
662 tri, err = mesh.Triangulate(xyz)
3742
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
663 if err != nil {
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
664 return nil, err
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
665 }
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
666 feedback.Info("Second triangulation took %v.", time.Since(start))
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
667 feedback.Info("Number triangles: %d.", len(tri.Triangles)/3)
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
668 feedback.Info("Clipping triangles from new mesh.")
879c297c47e9 SR import: Use home-brew concave hull algorithm in multi-beam scan case, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3733
diff changeset
669 }
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
670
4751
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
671 multibeam:
dbf07d0c364e SR import: If the point density is greater than 0.2 values per meter² the interpolating step is omitted.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4734
diff changeset
672
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
673 final := mesh.STRTree{Entries: 16}
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
674
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
675 if m.SurveyType != models.SurveyTypeMarking {
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
676
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
677 start = time.Now()
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
678 tin := tri.Tin()
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
679 tin.EPSG = epsg
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
680
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
681 var str mesh.STRTree
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
682 str.Build(tin)
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
683 feedback.Info("Building clipping index took %v", time.Since(start))
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
684
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
685 start = time.Now()
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
686
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
687 clippingPolygonBuffered.Indexify()
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
688 removed = str.Clip(&clippingPolygonBuffered)
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
689 feedback.Info("Clipping took %v.", time.Since(start))
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
690 feedback.Info("Number of triangles to clip %d.", len(removed))
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
691
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
692 start = time.Now()
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
693 final.BuildWithout(tin, removed)
4646
89a72e0e2f9b Add a method to serialize an STRTree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
694
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
695 feedback.Info("Building final mesh took %v.", time.Since(start))
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
696 feedback.Info("Store mesh.")
5419
202715173935 Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5418
diff changeset
697 } else {
202715173935 Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5418
diff changeset
698 start = time.Now()
202715173935 Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5418
diff changeset
699 clippingPolygonBuffered.Indexify()
5429
02a5da2f03b4 Fixed clipping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5428
diff changeset
700 before := len(xyz)
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
701 xyz = xyz.Filter(func(v mesh.Vertex) bool {
5429
02a5da2f03b4 Fixed clipping.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5428
diff changeset
702 return clippingPolygonBuffered.IntersectionBox2D(v.Box2D()) !=
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
703 mesh.IntersectionOutSide
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
704 })
5419
202715173935 Do clipping correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5418
diff changeset
705 feedback.Info("Clipping took %v.", time.Since(start))
5430
aa199f280f64 Cosmetics in logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5429
diff changeset
706 feedback.Info("Number of points to clip: %d.", before-len(xyz))
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
707 }
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
708
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
709 start = time.Now()
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
710
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
711 var (
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
712 id int64
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
713 dummy uint32
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
714 lat, lon float64
5473
93af8d1ea09f Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5458
diff changeset
715 hull []byte
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
716 )
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
717
5473
93af8d1ea09f Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5458
diff changeset
718 switch err := tx.QueryRowContext(
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
719 ctx,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
720 insertHullSQL,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
721 m.Bottleneck,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
722 m.Date.Time,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
723 m.DepthReference,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
724 nil,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
725 clippingPolygonWKB,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
726 epsg,
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
727 m.SurveyType,
5305
1a565f8a935a Adjusted Go code to establish ZPG exception during SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5035
diff changeset
728 zpgException,
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
729 ).Scan(
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
730 &id,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
731 &lat,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
732 &lon,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
733 &dummy,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
734 &hull,
5473
93af8d1ea09f Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5458
diff changeset
735 ); {
3664
58508f50d192 SR import: Made error messages symmetrical to multi beam if no matching bottleneck is found for single beam imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3659
diff changeset
736 case err == sql.ErrNoRows:
58508f50d192 SR import: Made error messages symmetrical to multi beam if no matching bottleneck is found for single beam imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3659
diff changeset
737 return nil, fmt.Errorf(
4177
8b75ac5e243e Made 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4171
diff changeset
738 "no matching bottleneck of given name or time available: %v", err)
3664
58508f50d192 SR import: Made error messages symmetrical to multi beam if no matching bottleneck is found for single beam imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3659
diff changeset
739 case err != nil:
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
740 return nil, err
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
741 }
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
742
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
743 if m.SurveyType != models.SurveyTypeMarking {
5679
03dfbe675842 Simplified version handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5678
diff changeset
744 final.OptimizeForSerialization(-1)
03dfbe675842 Simplified version handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5678
diff changeset
745
5595
bbc257dd9abf Mixed bad error handling found by staticcheck.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5585
diff changeset
746 var index []byte
5678
4abbb62d2bed Write mesh version to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5595
diff changeset
747 var version int
5679
03dfbe675842 Simplified version handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5678
diff changeset
748 index, version, err = final.Bytes(-1)
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
749 if err != nil {
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
750 return nil, err
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
751 }
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
752
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
753 h := sha1.New()
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
754 h.Write(index)
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
755 checksum := hex.EncodeToString(h.Sum(nil))
5678
4abbb62d2bed Write mesh version to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5595
diff changeset
756 _, err = tx.ExecContext(ctx, insertMeshSQL, id, checksum, index, version)
5411
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
757 if err != nil {
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
758 return nil, err
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
759 }
9822a840d668 Some refactoring to move marking handling to the right place in SR import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5410
diff changeset
760 feedback.Info("Storing mesh index took %s.", time.Since(start))
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
761 err = generateIsoAreas(
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
762 ctx, tx, feedback,
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
763 &final,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
764 loadClassBreaks(ctx, tx, feedback, final.Min().Z, final.Max().Z),
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
765 id)
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
766 } else { // SurveyTypeMarking
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
767 err = generateMarkingPoints(
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
768 ctx, tx, feedback,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
769 xyz, epsg,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
770 id)
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
771 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
772 if err != nil {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
773 return nil, err
3658
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
774 }
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
775
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
776 // Store for potential later removal.
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
777 if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil {
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
778 return nil, err
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
779 }
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
780
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
781 summary := struct {
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
782 Bottleneck string `json:"bottleneck"`
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
783 Date models.Date `json:"date"`
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
784 Lat float64 `json:"lat"`
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
785 Lon float64 `json:"lon"`
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
786 }{
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
787 Bottleneck: m.Bottleneck,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
788 Date: m.Date,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
789 Lat: lat,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
790 Lon: lon,
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
791 }
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
792
1c3df921361d Handle th case that a boundary polygon is uploaded along side with the single beam scan.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3655
diff changeset
793 return &summary, nil
3587
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
794 }
a9d140c7db8d SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3586
diff changeset
795
1498
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
796 // CleanUp removes the folder containing the ZIP file with the
5df748916fcf Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1496
diff changeset
797 // the sounding result import.
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
798 func (sr *SoundingResult) CleanUp() error {
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
799 return os.RemoveAll(sr.Dir)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
800 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
801
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
802 func (sr *SoundingResult) completeOverride() bool {
1384
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
803 // sr.EPSG == nil -> WGS84
3586
b9adb0ea4c41 SR import: a complete parameter overwrite now includes single beam flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3585
diff changeset
804 return sr.Bottleneck != nil &&
b9adb0ea4c41 SR import: a complete parameter overwrite now includes single beam flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3585
diff changeset
805 sr.Date != nil &&
b9adb0ea4c41 SR import: a complete parameter overwrite now includes single beam flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3585
diff changeset
806 sr.DepthReference != nil &&
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
807 (sr.SingleBeam != nil || sr.SurveyType != nil) &&
3946
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
808 sr.NegateZ != nil
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
809 }
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
810
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
811 func (sr *SoundingResult) loadMeta(f *zip.File) (*models.SoundingResultMeta, error) {
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
812 if f == nil {
1384
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
813 var epsg uint
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
814 if sr.EPSG != nil {
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
815 epsg = *sr.EPSG
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
816 } else {
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
817 epsg = models.WGS84
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
818 }
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
819
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
820 st := models.SurveyTypeMultiBeam
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
821 if sr.SingleBeam != nil && *sr.SingleBeam {
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
822 st = models.SurveyTypeSingleBeam
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
823 }
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
824 if sr.SurveyType != nil {
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
825 st = *sr.SurveyType
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
826 }
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
827
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
828 return &models.SoundingResultMeta{
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
829 Date: *sr.Date,
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
830 Bottleneck: *sr.Bottleneck,
1384
8d59457a5651 Sounding result import: Consider parameter override as complete even if there is no EPSG code. Use WGS84 in this case as a default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1338
diff changeset
831 EPSG: epsg,
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
832 DepthReference: *sr.DepthReference,
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
833 SurveyType: st,
3946
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
834 NegateZ: sr.negateZ(),
1292
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
835 }, nil
5aeda02c51b9 Sounding result import: Don't fail if an import ZIP does not contain an meta.json but has a full set of overrides.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1239
diff changeset
836 }
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
837 r, err := f.Open()
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
838 if err != nil {
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
839 return nil, err
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
840 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
841 defer r.Close()
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
842 var m models.SoundingResultMeta
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
843 if err := m.Decode(r); err != nil {
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
844 return nil, err
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
845 }
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
846
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
847 // Apply overrides
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
848 if sr.Date != nil {
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
849 m.Date = *sr.Date
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
850 }
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
851 if sr.Bottleneck != nil {
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
852 m.Bottleneck = *sr.Bottleneck
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
853 }
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
854 if sr.EPSG != nil {
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
855 m.EPSG = *sr.EPSG
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
856 }
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
857 if sr.DepthReference != nil {
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
858 m.DepthReference = *sr.DepthReference
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
859 }
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
860
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
861 // Kept in for compat
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
862 if sr.SingleBeam != nil {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
863 if *sr.SingleBeam {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
864 m.SurveyType = models.SurveyTypeSingleBeam
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
865 } else {
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
866 m.SurveyType = models.SurveyTypeMultiBeam
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
867 }
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
868 }
5403
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5315
diff changeset
869 if sr.SurveyType != nil {
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5315
diff changeset
870 m.SurveyType = *sr.SurveyType
3585
479da494bc09 SR import: access beam-type parameter supplied by client. TODO: Implement single beam code path.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3518
diff changeset
871 }
5458
e00b3296fc02 Fixed SR import: use meta.json for marking scans correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5430
diff changeset
872
3946
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
873 if sr.NegateZ != nil {
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
874 m.NegateZ = *sr.NegateZ
d668742c8978 SR import: Made `negate-z` flag more symmetrical to `single-beam` flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
875 }
1239
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
876
d842d9d10872 Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1225
diff changeset
877 return &m, nil
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
878 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
879
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
880 type vertexTransform func(mesh.Vertex) mesh.Vertex
3487
fdb0439850d5 Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3479
diff changeset
881
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
882 func identityTransform(v mesh.Vertex) mesh.Vertex { return v }
3945
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
883
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
884 func negateZTransform(v mesh.Vertex) mesh.Vertex {
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
885 return mesh.Vertex{X: v.X, Y: v.Y, Z: -v.Z}
3945
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
886 }
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
887
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
888 func chainTransforms(a, b vertexTransform) vertexTransform {
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
889 return func(v mesh.Vertex) mesh.Vertex { return b(a(v)) }
3945
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
890 }
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
891
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
892 func loadXYZReader(r io.Reader, feedback Feedback, xform vertexTransform) (mesh.MultiPointZ, error) {
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
893 mpz := make(mesh.MultiPointZ, 0, 250000)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
894 s := bufio.NewScanner(r)
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
895
4171
5a650cde0574 Move warning limiter to common package to flesh up the misc package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
896 warnLimiter := common.WarningLimiter{Log: feedback.Warn, MaxWarnings: 100}
3504
6e748f31777a AGM/SR import. Limit logging of warnings to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3487
diff changeset
897 warn := warnLimiter.Warn
6e748f31777a AGM/SR import. Limit logging of warnings to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3487
diff changeset
898 defer warnLimiter.Close()
2963
27ffd94afcb5 SR import: Limit number of warnings in parsing XYZ files to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2873
diff changeset
899
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
900 for line := 1; s.Scan(); line++ {
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
901 text := s.Text()
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
902 var p mesh.Vertex
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
903 // fmt.Sscanf(text, "%f,%f,%f") is 4 times slower.
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
904 idx := strings.IndexByte(text, ',')
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
905 if idx == -1 {
2963
27ffd94afcb5 SR import: Limit number of warnings in parsing XYZ files to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2873
diff changeset
906 warn("format error in line %d", line)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
907 continue
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
908 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
909 var err error
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
910 if p.X, err = strconv.ParseFloat(text[:idx], 64); err != nil {
2963
27ffd94afcb5 SR import: Limit number of warnings in parsing XYZ files to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2873
diff changeset
911 warn("format error in line %d: %v", line, err)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
912 continue
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
913 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
914 text = text[idx+1:]
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
915 if idx = strings.IndexByte(text, ','); idx == -1 {
1138
443fc80a315f Don't issue new lines at end of log messages when importing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1137
diff changeset
916 feedback.Warn("format error in line %d", line)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
917 continue
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
918 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
919 if p.Y, err = strconv.ParseFloat(text[:idx], 64); err != nil {
2963
27ffd94afcb5 SR import: Limit number of warnings in parsing XYZ files to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2873
diff changeset
920 warn("format error in line %d: %v", line, err)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
921 continue
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
922 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
923 text = text[idx+1:]
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
924 if p.Z, err = strconv.ParseFloat(text, 64); err != nil {
2963
27ffd94afcb5 SR import: Limit number of warnings in parsing XYZ files to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2873
diff changeset
925 warn("format error in line %d: %v", line, err)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
926 continue
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
927 }
3945
3bdbaf1b282a SR import: Negate the Z values in the XYZ files if the flag `negate-z` is set.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3904
diff changeset
928 p = xform(p)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
929 mpz = append(mpz, p)
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
930 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
931
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
932 if err := s.Err(); err != nil {
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
933 return nil, err
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
934 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
935
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
936 return mpz, nil
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
937 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
938
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
939 func loadXYZ(f *zip.File, feedback Feedback, xform vertexTransform) (mesh.MultiPointZ, error) {
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
940 r, err := f.Open()
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
941 if err != nil {
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
942 return nil, err
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
943 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
944 defer r.Close()
3487
fdb0439850d5 Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3479
diff changeset
945 return loadXYZReader(r, feedback, xform)
959
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
946 }
6ab012d0f0c2 Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
947
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
948 func loadXYZFile(f string, feedback Feedback, xform vertexTransform) (mesh.MultiPointZ, error) {
3748
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
949 r, err := os.Open(f)
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
950 if err != nil {
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
951 return nil, err
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
952 }
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
953 defer r.Close()
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
954 return loadXYZReader(r, feedback, xform)
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
955 }
4bb5dfa0b7e3 SR import: Accept TXT file for uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3742
diff changeset
956
1786
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1754
diff changeset
957 func loadBoundary(z *zip.ReadCloser) (polygonSlice, error) {
1225
4d7c44f7044e Factored out som zip lookup code to be reusable in sounding result upload controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
958 shpF := common.FindInZIP(z, ".shp")
960
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
959 if shpF == nil {
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
960 return nil, nil
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
961 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
962 prefix := strings.TrimSuffix(shpF.Name, path.Ext(shpF.Name))
1225
4d7c44f7044e Factored out som zip lookup code to be reusable in sounding result upload controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
963 dbfF := common.FindInZIP(z, prefix+".dbf")
960
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
964 if dbfF == nil {
4177
8b75ac5e243e Made 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4171
diff changeset
965 return nil, fmt.Errorf("no DBF file found for %s", shpF.Name)
960
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
966 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
967
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
968 shpR, err := shpF.Open()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
969 if err != nil {
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
970 return nil, err
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
971 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
972
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
973 dbfR, err := dbfF.Open()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
974 if err != nil {
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
975 shpR.Close()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
976 return nil, err
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
977 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
978 sr := shp.SequentialReaderFromExt(shpR, dbfR)
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
979 defer sr.Close()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
980
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
981 if !sr.Next() {
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
982 return nil, sr.Err()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
983 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
984
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
985 _, s := sr.Shape()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
986 if s == nil {
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
987 return nil, sr.Err()
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
988 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
989
972
17a03a84b0e8 Split out polygon code out of sounding result importer source file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 971
diff changeset
990 return shapeToPolygon(s)
960
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
991 }
e23ae2c83427 Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 959
diff changeset
992
5415
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
993 func defaultClassBreaks(min, max float64) mesh.ClassBreaks {
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
994 var heights mesh.ClassBreaks
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
995 h := contourStepWidth * math.Ceil(min/contourStepWidth)
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
996 for ; h <= max; h += contourStepWidth {
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
997 heights = append(heights, h)
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
998 }
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
999 return heights
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
1000 }
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
1001
5428
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1002 func generateMarkingPoints(
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1003 ctx context.Context,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1004 tx *sql.Tx,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1005 feedback Feedback,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1006 xyz mesh.MultiPointZ,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1007 epsg uint32,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1008 id int64,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1009 ) error {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1010 heights, err := mesh.LoadClassBreaks(
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1011 ctx, tx,
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1012 "morphology_classbreaks")
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1013
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1014 if err != nil {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1015 feedback.Warn("Loading class breaks failed: %v", err)
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1016 feedback.Info("Using default class breaks")
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1017 min, max := xyz.MinMax()
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1018 heights = defaultClassBreaks(min.Z, max.Z)
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1019 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1020
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1021 heights = heights.Dedup()
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1022
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1023 classes := heights.Classify(xyz)
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1024
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1025 stmt, err := tx.PrepareContext(ctx, insertMarkingPointsSQL)
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1026 if err != nil {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1027 return err
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1028 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1029 defer stmt.Close()
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1030
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1031 for i, class := range classes {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1032 // Ignore empty classes
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1033 if len(class) == 0 {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1034 continue
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1035 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1036 if _, err := stmt.ExecContext(
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1037 ctx, id, heights[i], epsg, class.AsWKB(),
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1038 ); err != nil {
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1039 return err
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1040 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1041 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1042
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1043 return nil
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1044 }
b8d5f1cd15fb Simplified classification. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5421
diff changeset
1045
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1046 func loadClassBreaks(
3591
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
1047 ctx context.Context,
062dc9b54b86 SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3587
diff changeset
1048 tx *sql.Tx,
3882
37d5c4441c70 Use custom morpho class breaks in sounding result contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3762
diff changeset
1049 feedback Feedback,
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1050 minZ, maxZ float64,
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1051 ) mesh.ClassBreaks {
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
1052
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
1053 heights, err := mesh.LoadClassBreaks(
3882
37d5c4441c70 Use custom morpho class breaks in sounding result contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3762
diff changeset
1054 ctx, tx,
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1055 "morphology_classbreaks")
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
1056
3882
37d5c4441c70 Use custom morpho class breaks in sounding result contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3762
diff changeset
1057 if err != nil {
37d5c4441c70 Use custom morpho class breaks in sounding result contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3762
diff changeset
1058 feedback.Warn("Loading class breaks failed: %v", err)
37d5c4441c70 Use custom morpho class breaks in sounding result contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3762
diff changeset
1059 feedback.Info("Using default class breaks")
5415
4ad68ab239b7 Factored creation of default class breaks in SR import to be reused with markings, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5412
diff changeset
1060 heights = defaultClassBreaks(minZ, maxZ)
3882
37d5c4441c70 Use custom morpho class breaks in sounding result contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3762
diff changeset
1061 } else {
5412
34bc6041e61e Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5411
diff changeset
1062 heights = heights.ExtrapolateClassBreaks(minZ, maxZ)
1184
064d44ccc6f2 Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents: 1168
diff changeset
1063 }
064d44ccc6f2 Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents: 1168
diff changeset
1064
5416
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1065 return heights.Dedup()
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1066 }
31b0e865e7a0 Stored marking points in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5415
diff changeset
1067
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1068 func generateIsoAreas(
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1069 ctx context.Context,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1070 tx *sql.Tx,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1071 feedback Feedback,
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
1072 tree *mesh.STRTree,
5412
34bc6041e61e Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5411
diff changeset
1073 heights mesh.ClassBreaks,
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1074 id int64,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1075 ) error {
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1076 feedback.Info("Generate iso areas")
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1077 total := time.Now()
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1078 defer func() {
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1079 feedback.Info("Generating iso areas took %s.",
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1080 time.Since(total))
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1081 }()
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1082
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
1083 box := mesh.Box2D{
4768
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1084 X1: tree.Min().X,
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1085 Y1: tree.Min().Y,
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1086 X2: tree.Max().X,
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1087 Y2: tree.Max().Y,
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1088 }
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1089
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4791
diff changeset
1090 raster := mesh.NewRaster(box, isoCellSize)
4768
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1091 raster.Rasterize(tree.Value)
a2f16bbcc846 Morph differences: Directly raster A and subtract B as a raster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4763
diff changeset
1092 areas := raster.Trace(heights)
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1093
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1094 return storeAreas(
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1095 ctx, tx, feedback,
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4646
diff changeset
1096 areas, tree.EPSG(), heights, id)
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1097 }
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1098
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1099 func storeAreas(
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1100 ctx context.Context,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1101 tx *sql.Tx,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1102 feedback Feedback,
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1103 areas []wkb.MultiPolygonGeom,
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1104 epsg uint32,
5412
34bc6041e61e Added a type for class breaks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5411
diff changeset
1105 heights mesh.ClassBreaks,
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1106 id int64,
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1107 ) error {
4564
6b107d4e6810 Add more debug output to trace problem why reprojected iso areas are not in expected bounds.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4563
diff changeset
1108 feedback.Info("Store iso areas.")
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1109 total := time.Now()
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1110 defer func() {
4564
6b107d4e6810 Add more debug output to trace problem why reprojected iso areas are not in expected bounds.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4563
diff changeset
1111 feedback.Info("Storing iso areas took %v.",
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1112 time.Since(total))
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1113 }()
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1114
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1115 stmt, err := tx.PrepareContext(ctx, insertIsoAreasSQL)
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1116 if err != nil {
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1117 return err
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1118 }
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1119 defer stmt.Close()
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1120
4637
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1121 var size int
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1122
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1123 for i, a := range areas {
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1124 if len(a) == 0 {
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1125 continue
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1126 }
4637
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1127 wkb := a.AsWKB()
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1128 size += len(wkb)
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1129 if _, err := stmt.ExecContext(
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1130 ctx,
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1131 id, heights[i], epsg,
4637
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1132 wkb,
4563
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1133 contourTolerance,
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1134 ); err != nil {
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1135 return err
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1136 }
a4042ab02e05 Store geometries in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4562
diff changeset
1137 }
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1138
4639
4380f5483c03 Log the size of the transferred WKB to database for differences, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4637
diff changeset
1139 feedback.Info("Transferred WKB size: %.2fMB.",
4637
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1140 float64(size)/(1024*1024))
0ed1489af8b6 Removed ST_MakeValid from inserting sounding results and differences ... in hope that they are not broken.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4629
diff changeset
1141
4562
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1142 return nil
5cc4042cf07c Started with integrating iso area generation into gemma server. WIP
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4256
diff changeset
1143 }