Mercurial > gemma
annotate pkg/imports/sr.go @ 3705:7006b92c0334
Handle updates (vs. historized and new versions) separately.
We need this distinction as updated data currently can not be
reviewed. More precisely: it can not be declined after review, as the
old data is updated in place.
The current exclusion from the review is a workaround and not meant to
be the final solution. Note that there are additional minor problems,
like the fact that the updated data is not counted as changed data for
the import.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Wed, 19 Jun 2019 17:00:08 +0200 |
parents | 58508f50d192 |
children | ec86a7155377 |
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" |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 "strconv" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 "strings" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 "time" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
960
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
35 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
|
36 |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
37 "gemma.intevation.de/gemma/pkg/common" |
3504
6e748f31777a
AGM/SR import. Limit logging of warnings to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3487
diff
changeset
|
38 "gemma.intevation.de/gemma/pkg/misc" |
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/models" |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 "gemma.intevation.de/gemma/pkg/octree" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 ) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
43 // 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
|
44 // 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
|
45 type SoundingResult struct { |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
46 // 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
|
47 // '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
|
48 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
|
49 |
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
|
50 // Override data |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
51 // 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
|
52 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
|
53 // 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
|
54 Bottleneck *string `json:"bottleneck,omitempty"` |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
55 // 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
|
56 // Defaults to WGS84. |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
57 EPSG *uint `json:"epsg,omitempty"` |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
58 // 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
|
59 // from the meta.json. |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
60 DepthReference *string `json:"depth-reference,omitempty"` |
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
|
61 // SingleBeam indicates that the sounding is a single beam scan. |
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
|
62 SingleBeam *bool `json:"single-beam,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
|
63 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
964
1e2dce348cfb
Serialize boundary polygon of sounding result as WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
961
diff
changeset
|
65 const ( |
1130
42617bba8709
Go from 50cm to 10cm stepwidth in calculating the contorlines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
66 contourStepWidth = 0.1 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
67 contourTolerance = 0.1 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
68 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
69 |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
70 const ( |
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
71 tooLongEdge = 50.0 |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
72 pointsPerSquareMeter = 2 |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
73 ) |
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
74 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
75 // SRJobKind is the unique name of a SoundingResult import job. |
991
a301d240905f
Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
76 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
|
77 |
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
|
78 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
|
79 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
80 func init() { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
81 RegisterJobCreator(SRJobKind, srJobCreator{}) |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
82 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
83 |
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
|
84 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
|
85 |
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
|
86 func (srJobCreator) AutoAccept() bool { return false } |
1646
a0982c38eac0
Import queue: Implemented email notifications.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1572
diff
changeset
|
87 |
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
|
88 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
|
89 |
3219
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2963
diff
changeset
|
90 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
|
91 return [2][]string{ |
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2963
diff
changeset
|
92 {"sounding_results", "sounding_results_contour_lines"}, |
4acbee65275d
Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2963
diff
changeset
|
93 {"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
|
94 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
95 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
96 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 id int64, |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
101 ) error { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
102 _, 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
|
103 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
|
104 } |
a301d240905f
Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
105 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
106 const ( |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
107 srStageDoneSQL = ` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
108 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
|
109 WHERE id = ( |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1900
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
114 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
|
115 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
|
116 bottleneck_id, |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
117 bottleneck_validity, |
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
|
118 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
|
119 depth_reference, |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
120 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
|
121 ) SELECT |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
122 bottleneck_id, |
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
123 validity, |
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
|
124 $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
|
125 $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
|
126 (SELECT |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 ST_MakeValid(ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326))::geography |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
131 END) |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
132 FROM waterway.bottlenecks |
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
133 WHERE objnam = $1 AND validity @> CAST($2 AS timestamptz) |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
134 RETURNING |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
135 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
|
136 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
|
137 ST_Y(ST_Centroid(area::geometry)), |
2833
1b6840093eac
Prevent calculation of wrong UTM zones
Tom Gottfried <tom@intevation.de>
parents:
2612
diff
changeset
|
138 best_utm(area), |
1b6840093eac
Prevent calculation of wrong UTM zones
Tom Gottfried <tom@intevation.de>
parents:
2612
diff
changeset
|
139 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
|
140 ` |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
972
diff
changeset
|
141 |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
142 reprojectPointsSQL = ` |
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
|
143 SELECT 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
|
144 |
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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
972
diff
changeset
|
151 insertOctreeSQL = ` |
1131
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
152 UPDATE waterway.sounding_results SET |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
153 octree_checksum = $2, octree_index = $3 |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
154 WHERE id = $1` |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
155 |
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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
161 insertContourSQL = ` |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
162 INSERT INTO waterway.sounding_results_contour_lines ( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
163 sounding_result_id, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
164 height, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
165 lines |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
166 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
167 SELECT |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
168 $1, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
169 $2, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
170 ST_Transform( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
171 ST_Multi( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
172 ST_CollectionExtract( |
1137
2fb6c0a6ec8a
Avoid intersection of each isoline with area on insert
Tom Gottfried <tom@intevation.de>
parents:
1136
diff
changeset
|
173 ST_SimplifyPreserveTopology( |
1410
eb82076fdffe
Sounding result import: Ensure that the generated iso-lines are valid.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1392
diff
changeset
|
174 ST_Multi(ST_Collectionextract( |
eb82076fdffe
Sounding result import: Ensure that the generated iso-lines are valid.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1392
diff
changeset
|
175 ST_MakeValid(ST_GeomFromWKB($4, $3::integer)), 2)), |
1137
2fb6c0a6ec8a
Avoid intersection of each isoline with area on insert
Tom Gottfried <tom@intevation.de>
parents:
1136
diff
changeset
|
176 $5 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
177 ), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
178 2 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
179 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
180 ), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
181 4326 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
182 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
183 FROM waterway.sounding_results sr |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
184 WHERE id = $1 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
185 ` |
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
|
186 |
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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 ON grwl.location = bns.gauge_location |
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
|
194 AND grwl.validity = bns.gauge_validity |
3645
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
195 WHERE bns.objnam = $1 |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
196 AND bns.validity @> CAST($2 AS timestamptz) |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
197 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
|
198 ` |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
199 |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 ` |
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
|
208 ) |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 |
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
|
210 func (sr *SoundingResult) isSingleBeam() bool { |
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
|
211 return sr.SingleBeam != nil && *sr.SingleBeam |
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
|
212 } |
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
|
213 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
214 // 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 ) (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
|
221 |
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
|
222 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
|
223 |
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
|
224 z, err := zip.OpenReader(filepath.Join(sr.Dir, "sr.zip")) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
225 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
|
226 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
|
227 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
228 defer z.Close() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
229 |
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
|
230 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
|
231 |
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
|
232 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
|
233 if mf == nil && !sr.completeOverride() { |
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
|
234 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
|
235 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
236 |
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
|
237 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
|
238 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
|
239 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
|
240 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
241 |
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
|
242 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
|
243 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
|
244 |
3487
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
245 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
|
246 |
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
|
247 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
|
248 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
|
249 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
|
250 var depthReference string |
3645
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
251 err := conn.QueryRowContext(ctx, |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
252 selectGaugeLDCSQL, |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
253 m.Bottleneck, |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
254 m.Date.Time, |
02951a62e8c6
'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents:
3609
diff
changeset
|
255 ).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
|
256 &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
|
257 &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
|
258 ) |
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
|
259 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
|
260 case err == sql.ErrNoRows: |
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
|
261 return nil, errors.New("Cannot load LDC value") |
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
|
262 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
|
263 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
|
264 } |
3487
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
265 xform = func(v octree.Vertex) octree.Vertex { |
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
266 return octree.Vertex{X: v.X, Y: v.Y, Z: ldc - v.Z} |
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
267 } |
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
|
268 m.DepthReference = depthReference |
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
|
269 } |
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
|
270 |
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
|
271 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
|
272 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
|
273 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
274 |
1528
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
275 var xyzf *zip.File |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
276 for _, ext := range []string{".xyz", ".txt"} { |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
277 feedback.Info("Looking for '*%s'", ext) |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
278 if xyzf = common.FindInZIP(z, ext); xyzf != nil { |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
279 break |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
280 } |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
281 } |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
282 if xyzf == nil { |
1528
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
283 return nil, errors.New("Cannot find any *.xyz or *.txt file") |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
284 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
285 |
3487
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
286 xyz, err := loadXYZ(xyzf, feedback, xform) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
287 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
|
288 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
|
289 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
290 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
291 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
|
292 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
|
293 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
294 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
295 // 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
|
296 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
|
297 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
|
298 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
|
299 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
300 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
305 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
|
306 |
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
|
307 var summary interface{} |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
308 |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
309 if sr.isSingleBeam() { |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
310 summary, err = sr.singleBeamScan( |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
311 ctx, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
312 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
|
313 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
|
314 importID, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
315 m, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
316 xyz, |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
317 boundary, |
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
|
318 ) |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
319 } else { |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
320 summary, err = sr.multiBeamScan( |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
321 ctx, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
322 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
|
323 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
|
324 importID, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
325 m, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
326 xyz, |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
327 boundary, |
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
|
328 ) |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
329 } |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
330 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
|
331 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
|
332 } |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
333 |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
334 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
|
335 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
|
336 "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
|
337 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
|
338 } |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
339 |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
340 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
|
341 "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
|
342 |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
343 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
|
344 } |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
345 |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
346 func (sr *SoundingResult) singleBeamScan( |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 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
|
351 m *models.SoundingResultMeta, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
352 xyz octree.MultiPointZ, |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
353 boundary polygonSlice, |
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
|
354 ) (interface{}, error) { |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
355 |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
356 feedback.Info("Processing as single beam scan.") |
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
|
357 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
|
358 |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
359 start := time.Now() |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
360 |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
361 xyzWKB := xyz.AsWKB() |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
362 var reproj []byte |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
363 var epsg uint |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
364 |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
365 if err := tx.QueryRowContext( |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
366 ctx, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
367 reprojectPointsSingleBeamSQL, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
368 xyzWKB, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
369 m.EPSG, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
370 ).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
|
371 return nil, err |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
372 } |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
373 |
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
|
374 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
|
375 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
|
376 } |
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
|
377 |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 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
|
382 |
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
|
383 start = time.Now() |
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
|
384 tri, err := octree.Triangulate(xyz) |
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
|
385 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
|
386 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
|
387 } |
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
|
388 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
|
389 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
|
390 |
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
|
391 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
|
392 clippingPolygon octree.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
|
393 clippingPolygonBuffered octree.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
|
394 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
|
395 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
|
396 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
|
397 ) |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
398 |
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
|
399 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
|
400 feedback.Info("No boundary given. Calulate from XYZ data.") |
3655
a6c671abbc35
Started with cleaning up the single beam import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3654
diff
changeset
|
401 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
|
402 |
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
|
403 var polygon octree.LineStringZ |
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
|
404 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
|
405 polygon, removed = tri.ConcaveHull(tooLongEdge) |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
406 |
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
|
407 polygonArea = polygon.Area() |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
408 if polygonArea < 0.0 { // counter clockwise |
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
409 polygonArea = -polygonArea |
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
410 polygon.Reverse() |
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
411 } |
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
412 |
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
|
413 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
|
414 |
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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 ).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
|
422 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
|
423 } |
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
|
424 |
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
|
425 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
|
426 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
|
427 } |
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
|
428 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
|
429 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
|
430 } |
c368a9a20478
Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3650
diff
changeset
|
431 |
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
|
432 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
|
433 |
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
|
434 } 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 ).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
|
444 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
|
445 } |
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
|
446 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
|
447 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
|
448 } |
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
|
449 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
|
450 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
|
451 } |
c368a9a20478
Tried to fix invalid new boundary polygon with ST_MakeValid() ... and failed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3650
diff
changeset
|
452 |
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
|
453 tin := tri.Tin() |
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
|
454 tin.EPSG = uint32(epsg) |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
455 |
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
456 var str octree.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
|
457 str.Build(tin) |
3655
a6c671abbc35
Started with cleaning up the single beam import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3654
diff
changeset
|
458 |
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
|
459 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
|
460 } |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
461 |
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
|
462 // Build the first mesh to generate random points on. |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
463 |
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
|
464 feedback.Info("Build virtual DEM based on original XYZ data.") |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
465 |
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
|
466 start = time.Now() |
3650
01ce3ba9b0d0
Fixed generating of random points.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3646
diff
changeset
|
467 |
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
|
468 var tree *octree.Tree |
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
|
469 { |
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
|
470 builder := octree.NewBuilder(tri.Tin()) |
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
|
471 builder.Build(removed) |
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
|
472 tree = builder.Tree() |
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
|
473 } |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
474 |
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
|
475 feedback.Info("Building took %v", time.Since(start)) |
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
|
476 |
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
|
477 feedback.Info("Boundary area: %.2fm²", polygonArea) |
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
|
478 |
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
|
479 numPoints := int(math.Ceil(polygonArea * pointsPerSquareMeter)) |
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
|
480 |
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
|
481 feedback.Info("Generate %d random points for an average density of ~%d points/m².", |
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
|
482 numPoints, pointsPerSquareMeter) |
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
|
483 |
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
|
484 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
|
485 |
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
|
486 generated := make(octree.LineStringZ, 0, numPoints+clippingPolygon.NumVertices(0)) |
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
|
487 |
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
|
488 tree.GenerateRandomVertices(numPoints, func(vertices []octree.Vertex) { |
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
|
489 generated = append(generated, vertices...) |
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
|
490 }) |
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
|
491 |
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
|
492 feedback.Info("Generating %d points took %v.", len(generated), time.Since(start)) |
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
|
493 |
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
|
494 // Add the boundary to new point cloud. |
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
|
495 dupes := map[[2]float64]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
|
496 clippingPolygon.Vertices(0, func(x, y 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
|
497 key := [2]float64{x, y} |
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
|
498 if _, found := dupes[key]; found { |
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
|
499 return |
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
|
500 } |
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
|
501 dupes[key] = 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
|
502 if z, ok := tree.Value(x, y); ok { |
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
|
503 generated = append(generated, octree.Vertex{X: x, Y: y, Z: z}) |
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
|
504 } |
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
|
505 }) |
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
|
506 |
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
|
507 feedback.Info("Triangulate new point cloud.") |
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
|
508 |
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
|
509 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
|
510 |
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
|
511 xyz = octree.MultiPointZ(generated) |
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
|
512 |
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
|
513 tri, err = octree.Triangulate(xyz) |
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
|
514 if 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
|
515 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
|
516 } |
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
|
517 feedback.Info("Second triangulation took %v.", time.Since(start)) |
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
|
518 feedback.Info("Number triangles: %d.", len(tri.Triangles)/3) |
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("Clipping triangles from new mesh.") |
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
|
520 |
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
|
521 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
|
522 tin := tri.Tin() |
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
|
523 tin.EPSG = uint32(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
|
524 |
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
|
525 var str octree.STRTree |
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
|
526 str.Build(tin) |
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
|
527 feedback.Info("Building STR tree took %v", time.Since(start)) |
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
|
528 |
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 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
|
530 |
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
|
531 clippingPolygonBuffered.Indexify() |
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 = str.Clip(&clippingPolygonBuffered) |
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 feedback.Info("Clipping STR tree took %v.", time.Since(start)) |
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 feedback.Info("Number of triangles to clip %d.", len(removed)) |
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 |
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
|
536 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
|
537 |
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("Build final octree index") |
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
|
539 |
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
|
540 builder := octree.NewBuilder(tin) |
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
|
541 builder.Build(removed) |
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
|
542 octreeIndex, err := builder.Bytes() |
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 if 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
|
544 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
|
545 } |
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 feedback.Info("Building octree took %v.", time.Since(start)) |
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
|
547 feedback.Info("Store octree.") |
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
|
548 |
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
|
549 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
|
550 |
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
|
551 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
|
552 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
|
553 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
|
554 lat, lon 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
|
555 ) |
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
|
556 |
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
|
557 var hull []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
|
558 |
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
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 ).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
|
569 &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
|
570 &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
|
571 &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
|
572 &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
|
573 &hull, |
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
|
574 ) |
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
|
575 |
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
|
576 switch { |
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
|
577 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
|
578 return nil, fmt.Errorf( |
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
|
579 "No matching bottleneck of given name or time available: %v", err) |
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
|
580 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
|
581 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
|
582 } |
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
|
583 |
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
|
584 h := sha1.New() |
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 h.Write(octreeIndex) |
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 checksum := hex.EncodeToString(h.Sum(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
|
587 _, err = tx.ExecContext(ctx, insertOctreeSQL, id, checksum, octreeIndex) |
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
|
588 if 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
|
589 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
|
590 } |
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
|
591 feedback.Info("Storing octree index took %s.", time.Since(start)) |
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 feedback.Info("Generate contour lines") |
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
|
593 |
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
|
594 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
|
595 err = generateContours(ctx, tx, builder.Tree(), 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
|
596 if 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
|
597 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
|
598 } |
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 feedback.Info("Generating contour lines took %s.", |
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
|
600 time.Since(start)) |
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
|
601 |
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
|
602 // 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
|
603 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
|
604 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
|
605 } |
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
|
606 |
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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 }{ |
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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 } |
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
|
618 |
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
|
619 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
|
620 } |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
621 |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
622 func (sr *SoundingResult) multiBeamScan( |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
623 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
|
624 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
|
625 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
|
626 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
|
627 m *models.SoundingResultMeta, |
a9d140c7db8d
SR import: Prepare the separate code paths for single and multibeam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3586
diff
changeset
|
628 xyz octree.MultiPointZ, |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
629 boundary polygonSlice, |
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
|
630 ) (interface{}, error) { |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
631 |
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
|
632 feedback.Info("Processing as multi beam scan.") |
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
|
633 var ( |
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
|
634 id int64 |
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
|
635 epsg uint32 |
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
|
636 lat, lon float64 |
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
|
637 ) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
638 start := time.Now() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
639 |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
640 var hull []byte |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
641 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
642 xyzWKB := xyz.AsWKB() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
643 |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
644 err := tx.QueryRowContext( |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
645 ctx, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
646 insertHullSQL, |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
647 m.Bottleneck, |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
648 m.Date.Time, |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
649 m.DepthReference, |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
650 xyzWKB, |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
651 boundary.asWKB(), |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
652 m.EPSG, |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
653 ).Scan( |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
654 &id, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
655 &lat, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
656 &lon, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
657 &epsg, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
658 &hull, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
659 ) |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
660 xyz, boundary = nil, nil // not need from now on. |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
661 feedback.Info("Calculating hull took %s.", time.Since(start)) |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
662 switch { |
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
663 case err == sql.ErrNoRows: |
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
664 return nil, fmt.Errorf( |
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
|
665 "No matching bottleneck of given name or time available: %v", err) |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
3645
diff
changeset
|
666 case err != nil: |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
667 return nil, err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
668 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
669 feedback.Info("Best suited UTM EPSG: %d", epsg) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
670 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
671 start = time.Now() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
672 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
673 var clippingPolygon octree.Polygon |
3646
810b28f59b8b
Generate random points for second mesh.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3609
diff
changeset
|
674 |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
675 if err := clippingPolygon.FromWKB(hull); err != nil { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
676 return nil, err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
677 } |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
678 clippingPolygon.Indexify() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
679 feedback.Info("Building clipping polygon took %v.", time.Since(start)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
680 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
681 start = time.Now() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
682 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
683 var reproj []byte |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
684 |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
685 if err = tx.QueryRowContext( |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
686 ctx, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
687 reprojectPointsSQL, |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
688 xyzWKB, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
689 m.EPSG, |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
690 epsg, |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
691 ).Scan(&reproj); 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
|
692 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
|
693 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
694 |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
695 if err := xyz.FromWKB(reproj); err != nil { |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
696 return nil, err |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
697 } |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
698 |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
699 feedback.Info("Reprojecting points took %v.", time.Since(start)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
700 feedback.Info("Number of reprojected points: %d", len(xyz)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
701 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
702 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
|
703 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
704 tri, err := octree.Triangulate(xyz) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
705 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
|
706 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
|
707 } |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
708 feedback.Info("Triangulation took %v.", time.Since(start)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
709 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
710 start = time.Now() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
711 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
712 tin := tri.Tin() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
713 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
714 var str octree.STRTree |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
715 str.Build(tin) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
716 feedback.Info("Building STR tree took %v", time.Since(start)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
717 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
718 start = time.Now() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
719 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
720 removed := str.Clip(&clippingPolygon) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
721 feedback.Info("Clipping STR tree took %v.", time.Since(start)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
722 feedback.Info("Number of triangles to clip %d.", len(removed)) |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
723 |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
724 start = time.Now() |
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
725 |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
726 tin.EPSG = epsg |
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
727 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
728 builder := octree.NewBuilder(tin) |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
729 builder.Build(removed) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
730 octreeIndex, err := builder.Bytes() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
731 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
|
732 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
|
733 } |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
734 feedback.Info("Building octree took %v.", time.Since(start)) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
735 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
736 start = time.Now() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
737 h := sha1.New() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
738 h.Write(octreeIndex) |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
739 checksum := hex.EncodeToString(h.Sum(nil)) |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
740 _, err = tx.ExecContext(ctx, insertOctreeSQL, id, checksum, octreeIndex) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
741 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
|
742 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
|
743 } |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
744 feedback.Info("Storing octree index took %s.", time.Since(start)) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
745 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
746 tree := builder.Tree() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
747 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
748 start = time.Now() |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
749 err = generateContours(ctx, tx, tree, id) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
750 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
|
751 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
|
752 } |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
753 feedback.Info("Generating and storing contour lines took %s.", |
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
754 time.Since(start)) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
755 |
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
|
756 // Store for potential later removal. |
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
|
757 if err = track(ctx, tx, importID, "waterway.sounding_results", id); 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
|
758 return nil, err |
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
|
759 } |
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
|
760 |
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
|
761 summary := struct { |
1900
6a67cd819e93
To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1786
diff
changeset
|
762 Bottleneck string `json:"bottleneck"` |
6a67cd819e93
To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1786
diff
changeset
|
763 Date models.Date `json:"date"` |
6a67cd819e93
To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1786
diff
changeset
|
764 Lat float64 `json:"lat"` |
6a67cd819e93
To prepare stretch import made some model data types re-usable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1786
diff
changeset
|
765 Lon float64 `json:"lon"` |
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
|
766 }{ |
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
|
767 Bottleneck: m.Bottleneck, |
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
|
768 Date: m.Date, |
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
|
769 Lat: lat, |
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
|
770 Lon: lon, |
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
|
771 } |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
772 |
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
773 return &summary, 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
|
774 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
775 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
776 // 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
|
777 // 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
|
778 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
|
779 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
|
780 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
781 |
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
|
782 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
|
783 // 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
|
784 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
|
785 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
|
786 sr.DepthReference != nil && |
b9adb0ea4c41
SR import: a complete parameter overwrite now includes single beam flag.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3585
diff
changeset
|
787 sr.SingleBeam != 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
|
788 } |
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
|
789 |
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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 } 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
|
796 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
|
797 } |
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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 DepthReference: *sr.DepthReference, |
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
|
803 }, 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
|
804 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
805 r, err := f.Open() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
806 if err != nil { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
807 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
808 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
809 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
|
810 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
|
811 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
|
812 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
|
813 } |
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
|
814 |
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
|
815 // 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
|
816 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
|
817 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
|
818 } |
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
|
819 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
|
820 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
|
821 } |
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
|
822 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
|
823 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
|
824 } |
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
|
825 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
|
826 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
|
827 } |
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
|
828 if sr.SingleBeam != nil { |
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
|
829 m.SingleBeam = *sr.SingleBeam |
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
|
830 } |
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
|
831 |
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
|
832 return &m, nil |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
833 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
834 |
3487
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
835 type vertexTransform func(octree.Vertex) octree.Vertex |
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
836 |
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
837 func loadXYZReader(r io.Reader, feedback Feedback, xform vertexTransform) (octree.MultiPointZ, error) { |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
838 mpz := make(octree.MultiPointZ, 0, 250000) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
839 s := bufio.NewScanner(r) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
840 |
2612
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
841 var hasNegZ bool |
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
842 |
3504
6e748f31777a
AGM/SR import. Limit logging of warnings to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3487
diff
changeset
|
843 warnLimiter := misc.WarningLimiter{Log: feedback.Warn, MaxWarnings: 100} |
6e748f31777a
AGM/SR import. Limit logging of warnings to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3487
diff
changeset
|
844 warn := warnLimiter.Warn |
6e748f31777a
AGM/SR import. Limit logging of warnings to 100.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3487
diff
changeset
|
845 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
|
846 |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
847 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
|
848 text := s.Text() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
849 var p octree.Vertex |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
850 // 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
|
851 idx := strings.IndexByte(text, ',') |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
852 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
|
853 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
|
854 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
855 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
856 var err error |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
857 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
|
858 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
|
859 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
860 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
861 text = text[idx+1:] |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
862 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
|
863 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
|
864 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
865 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
866 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
|
867 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
|
868 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
869 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
870 text = text[idx+1:] |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
871 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
|
872 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
|
873 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
874 } |
2612
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
875 if p.Z < 0 { |
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
876 p.Z = -p.Z |
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
877 if !hasNegZ { |
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
878 hasNegZ = true |
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
|
879 warn("Negative Z value found: Using -Z") |
2612
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
880 } |
c7ce8b011bcb
SR import: Negate negative Z values and issue a warning if a negative Z value is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2530
diff
changeset
|
881 } |
3487
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
882 if xform != nil { |
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
883 p = xform(p) |
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
884 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
885 mpz = append(mpz, p) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
886 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
887 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
888 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
|
889 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
890 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
891 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
892 return mpz, nil |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
893 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
894 |
3487
fdb0439850d5
Generalized transformation of vertices during sounding result import a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3479
diff
changeset
|
895 func loadXYZ(f *zip.File, feedback Feedback, xform vertexTransform) (octree.MultiPointZ, error) { |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
896 r, err := f.Open() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
897 if err != nil { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
898 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
899 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
900 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
|
901 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
|
902 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
903 |
1786
09349ca27dd7
Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
904 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
|
905 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
|
906 if shpF == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
907 return nil, nil |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
908 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
909 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
|
910 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
|
911 if dbfF == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
912 return nil, fmt.Errorf("No DBF file found for %s", shpF.Name) |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
913 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
914 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
915 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
|
916 if err != nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
917 return nil, err |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
918 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
919 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
920 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
|
921 if err != nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
922 shpR.Close() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
923 return nil, err |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
924 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
925 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
|
926 defer sr.Close() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
927 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
928 if !sr.Next() { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
929 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
|
930 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
931 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
932 _, s := sr.Shape() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
933 if s == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
934 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
|
935 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
936 |
972
17a03a84b0e8
Split out polygon code out of sounding result importer source file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
937 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
|
938 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
939 |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
940 func generateContours( |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
941 ctx context.Context, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
942 tx *sql.Tx, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
943 tree *octree.Tree, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
944 id int64, |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
945 ) error { |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
946 stmt, err := tx.PrepareContext(ctx, insertContourSQL) |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
947 if err != nil { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
948 return err |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
949 } |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
950 defer stmt.Close() |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
951 |
1184
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
952 // Adjust contour lines heights to multiples of contourStepWidth |
2530
3f61b84ae7a6
SR import: Set missing EPSG code to TIN.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2529
diff
changeset
|
953 var heights []float64 |
1184
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
954 h := contourStepWidth * math.Ceil(tree.Min.Z/contourStepWidth) |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
955 for ; h <= tree.Max.Z; h += contourStepWidth { |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
956 heights = append(heights, h) |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
957 } |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
958 |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
959 octree.DoContours(tree, heights, func(res *octree.ContourResult) { |
2529
45d51a49f191
SR import: Use own triangulation and clipping when importing sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2516
diff
changeset
|
960 if err == nil && len(res.Lines) > 0 { |
3591
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
961 _, err = stmt.ExecContext( |
062dc9b54b86
SR import: Using context.Context aware SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3587
diff
changeset
|
962 ctx, |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
963 id, res.Height, tree.EPSG, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
964 res.Lines.AsWKB2D(), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
965 contourTolerance) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
966 } |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
967 }) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
968 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
969 return err |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
970 } |