Mercurial > gemma
annotate pkg/imports/sr.go @ 1531:24445a618513
Added stub for bottleneck importer.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 07 Dec 2018 13:08:17 +0100 |
parents | 5874cedd7f91 |
children | 056a86b24be2 |
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" |
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/models" |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 "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
|
40 ) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
42 // 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
|
43 // 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
|
44 type SoundingResult struct { |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
45 // 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
|
46 // '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
|
47 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
|
48 |
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 // Override data |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
50 // Date if given overrides the date value from the meta.json. |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
51 Date *models.SoundingResultDate `json:"date,omitempty"` |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
52 // 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
|
53 Bottleneck *string `json:"bottleneck,omitempty"` |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
54 // 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
|
55 // Defaults to WGS84. |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
56 EPSG *uint `json:"epsg,omitempty"` |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
57 // 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
|
58 // from the meta.json. |
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
59 DepthReference *string `json:"depth-reference,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
|
60 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
964
1e2dce348cfb
Serialize boundary polygon of sounding result as WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
961
diff
changeset
|
62 const ( |
1130
42617bba8709
Go from 50cm to 10cm stepwidth in calculating the contorlines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
63 contourStepWidth = 0.1 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
64 contourTolerance = 0.1 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
65 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
66 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
67 // 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
|
68 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
|
69 |
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
|
70 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
|
71 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
72 func init() { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
73 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
|
74 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
75 |
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
|
76 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
|
77 sr := new(SoundingResult) |
1531
24445a618513
Added stub for bottleneck importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1528
diff
changeset
|
78 if err := common.FromJSONString(data, sr); err != nil { |
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
|
79 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
|
80 } |
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
|
81 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
|
82 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
83 |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
84 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
|
85 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
|
86 "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
|
87 "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
|
88 "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
|
89 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
90 } |
a5069da2f0b7
Independent imports in terms of affected tables/dependencies are now run concurrently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1131
diff
changeset
|
91 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 id int64, |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
96 ) error { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
97 _, 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
|
98 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
|
99 } |
a301d240905f
Decoupled import job creation and job execution with a factory function.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
988
diff
changeset
|
100 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
101 const ( |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
102 srStageDoneSQL = ` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
103 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
|
104 WHERE id = ( |
0abcc82ef976
Sounding results: Be a bit more precise when setting stageing_done.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1501
diff
changeset
|
105 SELECT key from waterway.track_imports |
0abcc82ef976
Sounding results: Be a bit more precise when setting stageing_done.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1501
diff
changeset
|
106 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
|
107 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
|
108 |
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 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 ) 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
|
117 (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
|
118 $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
|
119 $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
|
120 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
|
121 (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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 ) |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
129 RETURNING |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
130 id, |
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
|
131 ST_X(ST_Centroid(point_cloud::geometry)), |
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
|
132 ST_Y(ST_Centroid(point_cloud::geometry)), |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
133 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
|
134 32600 |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
135 ELSE |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
136 32700 |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
964
diff
changeset
|
137 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
|
138 |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
972
diff
changeset
|
139 insertOctreeSQL = ` |
1131
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
140 UPDATE waterway.sounding_results SET |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
141 octree_checksum = $2, octree_index = $3 |
2e6b47cdb2ca
Store octrees along with sounding results
Tom Gottfried <tom@intevation.de>
parents:
1130
diff
changeset
|
142 WHERE id = $1` |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
143 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
144 insertContourSQL = ` |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
145 INSERT INTO waterway.sounding_results_contour_lines ( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
146 sounding_result_id, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
147 height, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
148 lines |
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 SELECT |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
151 $1, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
152 $2, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
153 ST_Transform( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
154 ST_Multi( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
155 ST_CollectionExtract( |
1137
2fb6c0a6ec8a
Avoid intersection of each isoline with area on insert
Tom Gottfried <tom@intevation.de>
parents:
1136
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 $5 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
160 ), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
161 2 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
162 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
163 ), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
164 4326 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
165 ) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
166 FROM waterway.sounding_results sr |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
167 WHERE id = $1 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
168 ` |
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
|
169 ) |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
171 // 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 ) (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
|
178 |
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
|
179 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
|
180 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
|
181 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
|
182 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
183 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
|
184 |
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
|
185 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
|
186 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
|
187 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
|
188 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
|
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 |
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
|
191 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
|
192 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
|
193 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
|
194 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
195 |
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
|
196 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
|
197 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
|
198 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
199 |
1528
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 break |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
205 } |
5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1502
diff
changeset
|
206 } |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
207 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
|
208 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
|
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 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
211 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
|
212 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
|
213 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
|
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 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
|
217 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
|
218 } |
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 // 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
|
221 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
|
222 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
|
223 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
|
224 } |
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 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
|
227 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
|
228 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
|
229 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
230 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
|
231 |
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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 ) |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
237 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
|
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 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
|
240 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
|
241 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
|
242 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
|
243 xyz.AsWKB(), |
1496
3bf1f0de0763
Un-export point, line string and polygon types in import package as these are only used locally.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1410
diff
changeset
|
244 polygon.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
|
245 m.EPSG, |
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
|
246 ).Scan(&id, &lat, &lon, &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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
252 |
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
|
253 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
|
254 |
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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
262 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
263 if tin == 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
|
264 return nil, errors.New("cannot load TIN from database") |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
265 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
266 |
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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
277 |
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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 _, 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
|
284 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
|
285 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
|
286 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
|
287 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
288 |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
289 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
|
290 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
|
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 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
299 |
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
|
300 // 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
|
301 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
|
302 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
|
303 } |
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
|
304 |
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
|
305 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
|
306 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
|
307 } |
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
|
308 |
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
|
309 summary := struct { |
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
|
310 Bottleneck string `json:"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
|
311 Date models.SoundingResultDate `json:"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
|
312 Lat float64 `json:"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
|
313 Lon float64 `json:"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
|
314 }{ |
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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 } |
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
|
320 return &summary, 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
|
321 } |
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
322 |
1498
5df748916fcf
Finished API docs for sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1496
diff
changeset
|
323 // 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
|
324 // 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
|
325 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
|
326 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
|
327 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
328 |
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
|
329 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
|
330 // sr.EPSG == nil -> 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
|
331 return sr.Bottleneck != nil && sr.Date != nil && sr.DepthReference != 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
|
332 } |
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
|
333 |
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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 } 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
|
340 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
|
341 } |
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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 }, 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
|
348 } |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
349 r, err := f.Open() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
350 if err != nil { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
351 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
352 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 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
|
357 } |
d842d9d10872
Sounding result import: Added the feature to override bottleneck, EPSG, depth reference and date in meta.json by POST arguments.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1225
diff
changeset
|
358 |
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
|
359 // 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
|
360 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
|
361 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
|
362 } |
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
|
363 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
|
364 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
|
365 } |
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
|
366 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
|
367 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
|
368 } |
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
|
369 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
|
370 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
|
371 } |
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
|
372 |
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
|
373 return &m, nil |
959
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
374 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
375 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
376 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
|
377 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
|
378 s := bufio.NewScanner(r) |
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 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
|
381 text := s.Text() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 var p octree.Vertex |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 // 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
|
384 idx := strings.IndexByte(text, ',') |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 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
|
386 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
|
387 continue |
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 var err error |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
390 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
|
391 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
|
392 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
393 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
394 text = text[idx+1:] |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
395 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
|
396 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
|
397 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
398 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
399 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
|
400 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
|
401 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 text = text[idx+1:] |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 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
|
405 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
|
406 continue |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
407 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
408 mpz = append(mpz, p) |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
409 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
410 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
411 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
|
412 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
413 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
414 |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
415 return mpz, nil |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
416 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
417 |
988
7dfd3db94e6d
In preparation of persisting import jobs logging is done through an interface.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
984
diff
changeset
|
418 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
|
419 r, err := f.Open() |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
420 if err != nil { |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
421 return nil, err |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
422 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
423 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
|
424 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
|
425 } |
6ab012d0f0c2
Started with writing an importer job for sounding results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
426 |
1496
3bf1f0de0763
Un-export point, line string and polygon types in import package as these are only used locally.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1410
diff
changeset
|
427 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
|
428 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
|
429 if shpF == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
430 return nil, nil |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
431 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
432 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
|
433 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
|
434 if dbfF == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
435 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
|
436 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
437 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
438 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
|
439 if err != nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
440 return nil, err |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
441 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
442 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
443 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
|
444 if err != nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
445 shpR.Close() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
446 return nil, err |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
447 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
448 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
|
449 defer sr.Close() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
450 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
451 if !sr.Next() { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
452 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
|
453 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
454 |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
455 _, s := sr.Shape() |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
456 if s == nil { |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
457 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
|
458 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
459 |
972
17a03a84b0e8
Split out polygon code out of sounding result importer source file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
460 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
|
461 } |
e23ae2c83427
Load boundary polygon of sounding result from ZIP file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
959
diff
changeset
|
462 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
463 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
|
464 stmt, err := tx.Prepare(insertContourSQL) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
465 if err != nil { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
466 return err |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
467 } |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
468 defer stmt.Close() |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
469 |
1184
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
470 // 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
|
471 heights := make([]float64, 0) |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
472 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
|
473 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
|
474 heights = append(heights, h) |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
475 } |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
476 |
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1168
diff
changeset
|
477 octree.DoContours(tree, heights, func(res *octree.ContourResult) { |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
478 if err == nil { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
479 _, err = stmt.Exec( |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
480 id, res.Height, tree.EPSG, |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
481 res.Lines.AsWKB2D(), |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
482 contourTolerance) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
483 } |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
484 }) |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
485 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
486 return err |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
487 } |