Mercurial > gemma
annotate pkg/imports/sr.go @ 1339:1d1fc92fc3ea
Fixed authors in two schema files.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 26 Nov 2018 10:10:10 +0100 |
parents | 5bb1e3c1f364 |
children | 8d59457a5651 |
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" |
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
|
24 "encoding/json" |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "errors" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "fmt" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "io" |
1184
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
28 "math" |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 "os" |
960
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
30 "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
|
31 "path/filepath" |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 "strconv" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 "strings" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 "time" |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
960
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
36 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
|
37 |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
38 "gemma.intevation.de/gemma/pkg/common" |
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 |
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
|
43 type SoundingResult struct { |
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
|
44 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
|
45 |
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
|
46 // Override data |
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
|
47 Date *models.SoundingResultDate `json:"date,omitempty"` |
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 Bottleneck *string `json:"bottleneck,omitempty"` |
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 EPSG *uint `json:"epsg,omitempty"` |
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 DepthReference *string `json:"depth-reference,omitempty"` |
d842d9d10872
Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1225
diff
changeset
|
51 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
964
1e2dce348cfb
Serialize boundary polygon of sounding result as WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
961
diff
changeset
|
53 const ( |
1130
42617bba8709
Go from 50cm to 10cm stepwidth in calculating the contorlines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
54 contourStepWidth = 0.1 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
55 contourTolerance = 0.1 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
56 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
57 |
991
a301d240905f
Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
58 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
|
59 |
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
|
60 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
|
61 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
62 func init() { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
63 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
|
64 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
65 |
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
|
66 func (srJobCreator) Create(_ JobKind, data string) (Job, error) { |
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
|
67 sr := new(SoundingResult) |
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
|
68 if err := sr.FromString(data); 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
|
69 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
|
70 } |
d842d9d10872
Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1225
diff
changeset
|
71 return sr, nil |
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
|
72 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
73 |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
74 func (srJobCreator) Depends() []string { |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
75 return []string{ |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
76 "waterway.sounding_results", |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
77 "waterway.sounding_results_contour_lines", |
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 "waterway.bottlenecks", |
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 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
80 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
81 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 id int64, |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
86 ) error { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
87 _, 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
|
88 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
|
89 } |
a301d240905f
Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
90 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
91 const ( |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
92 srStageDoneSQL = ` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
93 UPDATE waterway.sounding_results SET staging_done = true |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
94 WHERE id = $1` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
95 |
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
|
96 insertPointsSQL = ` |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
97 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
|
98 bottleneck_id, |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
99 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
|
100 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
|
101 point_cloud, |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
102 area |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
103 ) VALUES ( |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
104 (SELECT bottleneck_id from waterway.bottlenecks where objnam = $1), |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
105 $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
|
106 $3, |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
107 ST_Transform(ST_GeomFromWKB($4, $6::integer), 4326)::geography, |
984
3c9ea8ab856a
Fixed small glitches in sounding result importer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
983
diff
changeset
|
108 (SELECT CASE WHEN $5::bytea IS NULL THEN |
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
|
109 ST_Transform( |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
110 ST_ConcaveHull( |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
111 ST_Force2D(ST_GeomFromWKB($4, $6::integer)), 0.7), 4326)::geography |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
112 ELSE |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
113 ST_Transform(ST_GeomFromWKB($5, $6::integer), 4326)::geography |
a4c92e0ef2e1
Stored point cloud and bounding area of sounding result in database. WIP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
960
diff
changeset
|
114 END) |
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 ) |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
116 RETURNING |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
117 id, |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
118 CASE WHEN ST_Y(ST_Centroid(point_cloud::geometry)) > 0 THEN |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
119 32600 |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
120 ELSE |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
121 32700 |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
122 END + floor((ST_X(ST_Centroid(point_cloud::geometry))+180)/6)::int + 1` |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
972
diff
changeset
|
123 |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
972
diff
changeset
|
124 insertOctreeSQL = ` |
1131
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
125 UPDATE waterway.sounding_results SET |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
126 octree_checksum = $2, octree_index = $3 |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
127 WHERE id = $1` |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
128 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
129 insertContourSQL = ` |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
130 INSERT INTO waterway.sounding_results_contour_lines ( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
131 sounding_result_id, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
132 height, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
133 lines |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
134 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
135 SELECT |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
136 $1, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
137 $2, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
138 ST_Transform( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
139 ST_Multi( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
140 ST_CollectionExtract( |
1137
2fb6c0a6ec8a
Avoid intersection of each isoline with area on insert
Tom Gottfried <tom@intevation.de>
parents:
1136
diff
changeset
|
141 ST_SimplifyPreserveTopology( |
2fb6c0a6ec8a
Avoid intersection of each isoline with area on insert
Tom Gottfried <tom@intevation.de>
parents:
1136
diff
changeset
|
142 ST_GeomFromWKB($4, $3::integer), |
2fb6c0a6ec8a
Avoid intersection of each isoline with area on insert
Tom Gottfried <tom@intevation.de>
parents:
1136
diff
changeset
|
143 $5 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
144 ), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
145 2 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
146 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
147 ), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
148 4326 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
149 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
150 FROM waterway.sounding_results sr |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
151 WHERE id = $1 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
152 ` |
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
|
153 ) |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
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
|
155 func (sr *SoundingResult) FromString(data string) 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
|
156 return json.NewDecoder(strings.NewReader(data)).Decode(sr) |
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
|
157 } |
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
|
158 |
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
|
159 func (sr *SoundingResult) ToString() (string, 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
|
160 var b strings.Builder |
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
|
161 if err := json.NewEncoder(&b).Encode(sr); 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
|
162 return "", 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
|
163 } |
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
|
164 return b.String(), 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
|
165 } |
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
|
166 |
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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 feedback Feedback, |
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
|
172 ) 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
|
173 |
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
|
174 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
|
175 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
176 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
177 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
178 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
|
179 |
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
|
180 feedback.Info("Looking for 'meta.json'") |
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
|
181 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
|
182 if mf == nil && !sr.completeOverride() { |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
183 return errors.New("Cannot find 'meta.json'") |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
184 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
185 |
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
|
186 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
|
187 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
188 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
189 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
190 |
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
|
191 if err := m.Validate(ctx, conn); err != nil { |
1224
bc4b642c8d04
Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
192 return 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
|
193 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
194 |
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
|
195 feedback.Info("Looking for '*.xyz'") |
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
|
196 xyzf := common.FindInZIP(z, ".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
|
197 if xyzf == nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
198 return errors.New("Cannot find any *.xyz file") |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
199 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
200 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
201 xyz, err := loadXYZ(xyzf, feedback) |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
202 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
203 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
204 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
205 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
206 if len(xyz) == 0 { |
1330
785f14264426
Follow the rules for error messages to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
207 return 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
|
208 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
209 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
210 // Is there a boundary shapefile in the ZIP archive? |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
211 polygon, err := loadBoundary(z) |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
212 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
213 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
214 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
215 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
216 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
|
217 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
218 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
219 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
220 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
|
221 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
222 var id int64 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
223 var epsg uint32 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
224 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
|
225 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
226 err = tx.QueryRow(insertPointsSQL, |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
227 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
|
228 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
|
229 m.DepthReference, |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
230 xyz.AsWKB(), |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
231 polygon.AsWBK(), |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
232 m.EPSG, |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
233 ).Scan(&id, &epsg) |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
234 xyz, polygon = nil, nil // not need from now on. |
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
|
235 feedback.Info("storing points 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
|
236 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
237 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
238 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
239 |
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
|
240 feedback.Info("Best suited UTM EPSG: %d", epsg) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
241 |
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
|
242 feedback.Info("Triangulate...") |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
243 start = time.Now() |
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
|
244 tin, err := octree.GenerateTinByID(ctx, conn, id, epsg) |
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
|
245 feedback.Info("triangulation 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
|
246 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
247 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
248 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
249 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
250 if tin == nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
251 return errors.New("cannot load TIN from database") |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
252 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
253 |
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
|
254 feedback.Info("Building octree...") |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
255 builder := octree.NewBuilder(tin) |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
256 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
|
257 builder.Build() |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
258 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
|
259 tin = nil // not needed from now on |
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
|
260 feedback.Info("building octree 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
|
261 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
262 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
263 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
264 |
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
|
265 feedback.Info("Store octree...") |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 checksum := hex.EncodeToString(h.Sum(nil)) |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
270 _, err = tx.Exec(insertOctreeSQL, id, checksum, octreeIndex) |
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
|
271 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
|
272 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
273 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
274 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
275 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
276 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
|
277 builder = nil // not needed from now on |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
278 |
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
|
279 feedback.Info("Generate contour lines...") |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
280 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
|
281 err = generateContours(tree, tx, id) |
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
|
282 feedback.Info("generating and storing contour lines 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
|
283 if err != nil { |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
284 return err |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
285 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
286 |
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
|
287 // 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
|
288 if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil { |
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
|
289 return err |
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
|
290 } |
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
|
291 |
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
|
292 if err = tx.Commit(); err == nil { |
443fc80a315f
Don't issue new lines at end of log messages when importing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1137
diff
changeset
|
293 feedback.Info("Storing sounding result was successful.") |
443fc80a315f
Don't issue new lines at end of log messages when importing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1137
diff
changeset
|
294 } |
443fc80a315f
Don't issue new lines at end of log messages when importing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1137
diff
changeset
|
295 return 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
|
296 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
297 |
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
|
298 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
|
299 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
|
300 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
301 |
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
|
302 func (sr *SoundingResult) completeOverride() bool { |
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
|
303 return sr.EPSG != nil && sr.Bottleneck != nil && sr.Date != nil && sr.DepthReference != 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
|
304 } |
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
|
305 |
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
|
306 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
|
307 if f == 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
|
308 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
|
309 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
|
310 Bottleneck: *sr.Bottleneck, |
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
|
311 EPSG: *sr.EPSG, |
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
|
312 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
|
313 }, 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
|
314 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 r, err := f.Open() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
316 if err != nil { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
318 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 } |
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
|
324 |
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
|
325 // 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
|
326 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
|
327 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
|
328 } |
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
|
329 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
|
330 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
|
331 } |
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
|
332 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
|
333 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
|
334 } |
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
|
335 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
|
336 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
|
337 } |
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
|
338 |
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
|
339 return &m, nil |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
340 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
341 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
342 func loadXYZReader(r io.Reader, feedback Feedback) (octree.MultiPointZ, error) { |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 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
|
344 s := bufio.NewScanner(r) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
345 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
346 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
|
347 text := s.Text() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
348 var p octree.Vertex |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
349 // 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
|
350 idx := strings.IndexByte(text, ',') |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
351 if 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
|
352 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
|
353 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
354 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
355 var err error |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
356 if p.X, err = strconv.ParseFloat(text[:idx], 64); err != nil { |
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
|
357 feedback.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
|
358 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
359 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
360 text = text[idx+1:] |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
361 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
|
362 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
|
363 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
364 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
365 if p.Y, err = strconv.ParseFloat(text[:idx], 64); err != nil { |
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
|
366 feedback.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
|
367 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
368 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
369 text = text[idx+1:] |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
370 if p.Z, err = strconv.ParseFloat(text, 64); err != nil { |
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
|
371 feedback.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
|
372 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
373 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
374 mpz = append(mpz, p) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
375 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
376 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
377 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
|
378 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
379 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
380 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 return mpz, nil |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
384 func loadXYZ(f *zip.File, feedback Feedback) (octree.MultiPointZ, error) { |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 r, err := f.Open() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
386 if err != nil { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
387 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
388 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
389 defer r.Close() |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
390 return loadXYZReader(r, feedback) |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
391 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
392 |
960
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
393 func loadBoundary(z *zip.ReadCloser) (Polygon, 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
|
394 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
|
395 if shpF == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
396 return nil, nil |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
397 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
398 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
|
399 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
|
400 if dbfF == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
401 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
|
402 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
403 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
404 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
|
405 if err != nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
406 return nil, err |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
407 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
408 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
409 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
|
410 if err != nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
411 shpR.Close() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
412 return nil, err |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
413 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
414 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
|
415 defer sr.Close() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
416 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
417 if !sr.Next() { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
418 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
|
419 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
420 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
421 _, s := sr.Shape() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
422 if s == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
423 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
|
424 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
425 |
972
17a03a84b0e8
Split out polygon code out of sounding result importer source file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
426 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
|
427 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
428 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
429 func generateContours(tree *octree.Tree, tx *sql.Tx, id int64) error { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
430 stmt, err := tx.Prepare(insertContourSQL) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
431 if err != nil { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
432 return err |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
433 } |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
434 defer stmt.Close() |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
435 |
1184
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
436 // Adjust contour lines heights to multiples of contourStepWidth |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
437 heights := make([]float64, 0) |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
438 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
|
439 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
|
440 heights = append(heights, h) |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
441 } |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
442 |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
443 octree.DoContours(tree, heights, func(res *octree.ContourResult) { |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
444 if err == nil { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
445 _, err = stmt.Exec( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
446 id, res.Height, tree.EPSG, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
447 res.Lines.AsWKB2D(), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
448 contourTolerance) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
449 } |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
450 }) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
451 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
452 return err |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
453 } |