Mercurial > gemma
annotate cmd/octree2contour/store.go @ 792:ce23a4192788
Removed dead code.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 27 Sep 2018 09:55:25 +0200 |
parents | fb9faf2c4f60 |
children | 271561dce2e6 |
rev | line source |
---|---|
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package main |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 "database/sql" |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
5 "time" |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
7 "gemma.intevation.de/gemma/pkg/octree" |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 ) |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 type result struct { |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 h float64 |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
12 lines octree.MultiLineStringZ |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 } |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
15 const ( |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
16 deleteSQL = ` |
735
83a9f04f1759
Spell table names correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
732
diff
changeset
|
17 DELETE FROM waterway.sounding_results_contour_lines |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
18 WHERE sounding_result_id IN (SELECT id |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
19 FROM waterway.sounding_results |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
20 WHERE bottleneck_id = $1 AND date_info = $2) |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 ` |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
22 insertSQL = ` |
735
83a9f04f1759
Spell table names correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
732
diff
changeset
|
23 INSERT INTO waterway.sounding_results_contour_lines |
736
34ea9d5df653
Fixed problem with unique constraint for countour lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
735
diff
changeset
|
24 (sounding_result_id, height, lines) |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
25 SELECT |
742
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
26 sr.id, |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
27 $1, |
742
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
28 ST_Transform( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
29 ST_Translate( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
30 ST_Force3D( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
31 ST_CollectionExtract( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
32 ST_Force2D( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
33 ST_Intersection( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
34 ST_Transform(sr.area::geometry, $3::integer), |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
35 ST_SetSRID( |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
36 ST_GeomFromWKB($2), $3::integer))), 2)), 0.0, 0.0, $1::numeric), |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
37 4326)::geography |
fb9faf2c4f60
Clip contour lines against bounding area of sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
736
diff
changeset
|
38 FROM waterway.sounding_results sr |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
39 WHERE bottleneck_id = $4 AND date_info = $5 |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
40 ` |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
41 ) |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
43 func store( |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
44 all []result, epsg uint32, |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
45 bottleneck string, date time.Time, |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
46 ) error { |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 return run(func(db *sql.DB) error { |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 tx, err := db.Begin() |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 if err != nil { |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 return err |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 defer tx.Rollback() |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
56 if _, err := tx.Exec(deleteSQL, bottleneck, date); err != nil { |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
57 return err |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
58 } |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
59 |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 stmt, err := tx.Prepare(insertSQL) |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 if err != nil { |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 return err |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 for _, r := range all { |
732
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
66 if _, err := stmt.Exec( |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
67 r.h, r.lines.AsWKB(), epsg, |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
68 bottleneck, date, |
39b5cf9a6b8f
Store sounding results contour lines into right table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
727
diff
changeset
|
69 ); err != nil { |
694
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return err |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return tx.Commit() |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 }) |
a9783d8f74ed
octree: Store contour lines into postgres/postgis.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |