Mercurial > gemma
annotate pkg/controllers/diff.go @ 3830:464a6a6e05e6 sld-colors
Clean color handling a bit.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 04 Jul 2019 11:03:36 +0200 |
parents | 2a079d0a71c1 |
children | 0b382767b5ab |
rev | line source |
---|---|
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018, 2019 by via donau |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "database/sql" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "fmt" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "log" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "net/http" |
2574
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
21 "sync" |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "time" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "golang.org/x/sync/semaphore" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/common" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/models" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "gemma.intevation.de/gemma/pkg/octree" |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 ) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
31 const ( |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
32 contourTolerance = 0.1 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
33 contourStep = 0.1 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
34 ) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
35 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
36 const ( |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
37 diffIDSQL = ` |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
38 SELECT sd.id FROM |
3656
2a079d0a71c1
Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents:
2587
diff
changeset
|
39 caching.sounding_differences sd JOIN |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
40 waterway.sounding_results srm ON sd.minuend = srm.id JOIN |
2587
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
41 waterway.sounding_results srs ON sd.subtrahend = srs.id |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
42 WHERE srm.bottleneck_id = srs.bottleneck_id AND |
2587
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
43 srm.bottleneck_id = $1 AND |
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
44 srm.date_info = $2::date AND |
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
45 srs.date_info = $3::date |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
46 ` |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
47 insertDiffSQL = ` |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
48 WITH soundings AS ( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
49 SELECT sr.id AS id, sr.date_info AS date_info FROM |
2587
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
50 waterway.sounding_results sr |
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
51 WHERE sr.bottleneck_id = $1 |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
52 ) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
53 INSERT INTO caching.sounding_differences (minuend, subtrahend) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
54 SELECT m.id, s.id FROM soundings m, soundings s |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
55 WHERE m.date_info = $2::date AND s.date_info = $3::date |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
56 RETURNING id |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
57 ` |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
58 insertDiffContourSQL = ` |
2587
857bb070b9f1
Morphological differences: Bottleneck_id is an integer represented as a string.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2585
diff
changeset
|
59 INSERT INTO caching.sounding_differences_contour_lines ( |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
60 sounding_differences_id, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
61 height, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
62 lines |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
63 ) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
64 SELECT |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
65 $5, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
66 $4, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
67 ST_Transform( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
68 ST_Multi( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
69 ST_CollectionExtract( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
70 ST_SimplifyPreserveTopology( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
71 ST_Multi(ST_Collectionextract( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
72 ST_MakeValid(ST_GeomFromWKB($1, $2::integer)), 2)), |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
73 $3 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
74 ), |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
75 2 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
76 ) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
77 ), |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
78 4326 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
79 ) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
80 ` |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
81 ) |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
82 |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 // Only allow three diffence calculation at once. |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 // TODO: Make this configurable? |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 var diffCalculationSemaphore = semaphore.NewWeighted(int64(3)) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 func diffCalculation( |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 input interface{}, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 req *http.Request, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 conn *sql.Conn, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 ) (jr JSONResult, err error) { |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
93 begin := time.Now() |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
94 start := begin |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
2584
0c400404a237
Morphological differences: Fixed type assertion for input json.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2583
diff
changeset
|
96 dci := input.(*models.DiffCalculationInput) |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
97 |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 ctx := req.Context() |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
100 var id int64 |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
101 err = conn.QueryRowContext( |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
102 ctx, |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
103 diffIDSQL, |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
104 dci.Bottleneck, |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
105 dci.Minuend.Time, |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
106 dci.Subtrahend.Time, |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
107 ).Scan(&id) |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
108 |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
109 switch { |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
110 case err == sql.ErrNoRows: |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
111 // We need to calculate it. |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
112 case err != nil: |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
113 return |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
114 default: |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
115 // We already have this diff |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
116 jr = JSONResult{ |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
117 Result: map[string]int64{"id": id}, |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
118 } |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
119 return |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
120 } |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
121 |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 // DoS counter measure. |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 if err = diffCalculationSemaphore.Acquire(ctx, 1); err != nil { |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 return |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 defer diffCalculationSemaphore.Release(1) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 minuendTree, err := octree.FromCache( |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 ctx, conn, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 dci.Bottleneck, dci.Minuend.Time) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 log.Printf("info: loading minuend octree took %s\n", time.Since(start)) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 if err != nil { |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 return |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 if minuendTree == nil { |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 err = JSONError{ |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 Code: http.StatusNotFound, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 Message: fmt.Sprintf("Cannot find survey for %s/%s.", |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 dci.Bottleneck, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 dci.Minuend.Format(common.DateFormat)), |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 return |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 start = time.Now() |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 subtrahendTree, err := octree.FromCache( |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 ctx, conn, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 dci.Bottleneck, dci.Subtrahend.Time) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 log.Printf("info: loading subtrahend octree took %s\n", time.Since(start)) |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 if err != nil { |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 return |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 if subtrahendTree == nil { |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 err = JSONError{ |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 Code: http.StatusNotFound, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 Message: fmt.Sprintf("Cannot find survey for %s/%s.", |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 dci.Bottleneck, |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 dci.Subtrahend.Format(common.DateFormat)), |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 return |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 } |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 |
2572
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
168 // We need a slow path implementation for this. |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
169 if minuendTree.EPSG != subtrahendTree.EPSG { |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
170 err = JSONError{ |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
171 Code: http.StatusInternalServerError, |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
172 Message: "Calculating differences between two different " + |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
173 "EPSG code octrees are not supported, yet.", |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
174 } |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
175 return |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
176 } |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
177 |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
178 start = time.Now() |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
179 points := minuendTree.Diff(subtrahendTree) |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
180 log.Printf("info: A - B took %v\n", time.Since(start)) |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
181 |
2574
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
182 // The Triangulation and the loading of the clipping |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
183 // polygon can be done concurrently. |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
184 |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
185 jobs := make(chan func()) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
186 |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
187 wg := new(sync.WaitGroup) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
188 for i := 0; i < 2; i++ { |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
189 wg.Add(1) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
190 go func() { |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
191 defer wg.Done() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
192 for job := range jobs { |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
193 job() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
194 } |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
195 }() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
196 } |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
197 |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
198 var ( |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
199 tri *octree.Triangulation |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
200 triErr error |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
201 clip *octree.Polygon |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
202 clipErr error |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
203 ) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
204 |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
205 jobs <- func() { |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
206 start := time.Now() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
207 tri, triErr = points.Triangulate() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
208 log.Printf("info: triangulation took %v\n", time.Since(start)) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
209 } |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
210 |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
211 jobs <- func() { |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
212 start := time.Now() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
213 clip, clipErr = octree.LoadClippingPolygon( |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
214 ctx, conn, |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
215 minuendTree.EPSG, |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
216 dci.Bottleneck, |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
217 dci.Minuend.Time, |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
218 dci.Subtrahend.Time) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
219 log.Printf("info: loading clipping polygon took %v\n", time.Since(start)) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
220 } |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
221 close(jobs) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
222 wg.Wait() |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
223 |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
224 switch { |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
225 case triErr != nil && clipErr != nil: |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
226 err = fmt.Errorf("%v %v", triErr, clipErr) |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
227 return |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
228 case triErr != nil: |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
229 err = triErr |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
230 return |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
231 case clipErr != nil: |
2833ff156cb2
Morphological differences: Moved loading of clipping polygon into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2572
diff
changeset
|
232 err = clipErr |
2572
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
233 return |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
234 } |
7686c7c23506
Morphological differences: Moved some code into octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2570
diff
changeset
|
235 |
2575
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
236 start = time.Now() |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
237 tin := tri.Tin() |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
238 removed := tin.Clip(clip) |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
239 log.Printf("info: clipping TIN took %v\n", time.Since(start)) |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
240 |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
241 start = time.Now() |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
242 log.Printf("info: Number of triangles to clip: %d\n", len(removed)) |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
243 builder := octree.NewBuilder(tin) |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
244 builder.Build(removed) |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
245 log.Printf("info: building octree took %v\n", time.Since(start)) |
59e7a011d347
Morphological differences: Moved TIN clipping to octree package and hide the technical details there.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2574
diff
changeset
|
246 |
2576
647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2575
diff
changeset
|
247 tree := builder.Tree() |
647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2575
diff
changeset
|
248 |
647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2575
diff
changeset
|
249 log.Printf("info: min/max: %f %f\n", tree.Min.Z, tree.Max.Z) |
647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2575
diff
changeset
|
250 |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
251 heights := octree.SampleDiffHeights( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
252 tree.Min.Z, tree.Max.Z, contourStep) |
2576
647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2575
diff
changeset
|
253 log.Printf("info: num heights: %d\n", len(heights)) |
647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2575
diff
changeset
|
254 |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
255 start = time.Now() |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
256 |
2580
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
257 // XXX: Maybe we should start this transaction earlier!? |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
258 var tx *sql.Tx |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
259 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
260 return |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
261 } |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
262 defer tx.Rollback() |
5125db802b79
Morphological differences: Check if we already have a diff before we start to calculate it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2576
diff
changeset
|
263 |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
264 var stmt *sql.Stmt |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
265 if stmt, err = tx.PrepareContext(ctx, insertDiffContourSQL); err != nil { |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
266 return |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
267 } |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
268 defer stmt.Close() |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
269 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
270 if err = tx.QueryRowContext( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
271 ctx, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
272 insertDiffSQL, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
273 dci.Bottleneck, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
274 dci.Minuend.Time, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
275 dci.Subtrahend.Time, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
276 ).Scan(&id); err != nil { |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
277 return |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
278 } |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 |
2583
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
280 octree.DoContours(tree, heights, func(res *octree.ContourResult) { |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
281 if err == nil && len(res.Lines) > 0 { |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
282 _, err = stmt.ExecContext( |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
283 ctx, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
284 res.Lines.AsWKB2D(), |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
285 minuendTree.EPSG, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
286 contourTolerance, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
287 res.Height, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
288 id, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
289 ) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
290 } |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
291 }) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
292 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
293 log.Printf("info: calculating and storing iso lines took %v\n", |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
294 time.Since(start)) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
295 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
296 if err != nil { |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
297 return |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
298 } |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
299 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
300 if err = tx.Commit(); err != nil { |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
301 log.Printf("info: difference calculation failed after %v\n", |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
302 time.Since(begin)) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
303 return |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
304 } |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
305 log.Printf("info: difference calculation succeed after %v\n", |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
306 time.Since(begin)) |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
307 |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
308 jr = JSONResult{ |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
309 Result: map[string]int64{"id": id}, |
5c6a7e69b02d
Morphological differences: Store calculated iso-lines in database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2580
diff
changeset
|
310 } |
2570
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 return |
c4242b9d59fe
Morphological differences: Added endpoint stub POST /api/diff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
312 } |