Mercurial > gemma
annotate pkg/controllers/cross.go @ 4931:e41d42be0e13 fairway-marks-import
One more callback to avoid code duplication more consequently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 14 Feb 2020 19:34:08 +0100 |
parents | f4abfd0ee8ad |
children | 5f47eeea988d |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
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:
838
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:
838
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
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:
838
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:
838
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
838
diff
changeset
|
13 |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "context" |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
834
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
19 "fmt" |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "log" |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "net/http" |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "time" |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/mesh" |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/models" |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
26 |
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
27 mw "gemma.intevation.de/gemma/pkg/middleware" |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ) |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 func reproject( |
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:
1182
diff
changeset
|
31 ctx context.Context, |
762
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
32 rp *models.Reprojector, |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
33 src models.GeoJSONLineCoordinates, |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 ) (models.GeoJSONLineCoordinates, error) { |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 dst := make(models.GeoJSONLineCoordinates, len(src)) |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 for i, s := range src { |
762
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
38 var err error |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
39 if dst[i].Lat, dst[i].Lon, err = rp.Reproject( |
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:
1182
diff
changeset
|
40 ctx, |
d753ce6cf588
To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1182
diff
changeset
|
41 s.Lat, s.Lon, |
762
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
42 ); err != nil { |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 return nil, err |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 } |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 return dst, nil |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
1182
936dd3714325
cross sections: As the triangles in the octree are already clipped against the area
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
49 const projectBackSQL = ` |
936dd3714325
cross sections: As the triangles in the octree are already clipped against the area
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
50 SELECT ST_AsBinary( |
936dd3714325
cross sections: As the triangles in the octree are already clipped against the area
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
51 ST_Transform(ST_GeomFromWKB($2, $1::integer), 4326))` |
766
afc635ab9f5b
Project the result data of the cross sections which are calculated in UTM back to WGS84.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
763
diff
changeset
|
52 |
1182
936dd3714325
cross sections: As the triangles in the octree are already clipped against the area
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
53 func projectBack( |
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:
1182
diff
changeset
|
54 ctx context.Context, |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
55 line mesh.MultiLineStringZ, |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
56 epsg uint32, |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
57 conn *sql.Conn, |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
58 ) (models.GeoJSONMultiLineCoordinatesZ, error) { |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
59 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
60 var mls models.GeoJSONMultiLineCoordinatesZ |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
61 err := conn.QueryRowContext( |
1182
936dd3714325
cross sections: As the triangles in the octree are already clipped against the area
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
62 ctx, projectBackSQL, |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
63 epsg, line.AsWKB(), |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
64 ).Scan(&mls) |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
65 |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
66 return mls, err |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
67 } |
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
68 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
69 func crossSection(req *http.Request) (jr mw.JSONResult, err error) { |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
71 csi := mw.JSONInput(req).(*models.CrossSectionInput) |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 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:
1182
diff
changeset
|
74 ctx := req.Context() |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
75 conn := mw.JSONConn(req) |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
77 tree, err := mesh.FromCache( |
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:
1182
diff
changeset
|
78 ctx, conn, |
d753ce6cf588
To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1182
diff
changeset
|
79 csi.Properties.Bottleneck, csi.Properties.Date.Time) |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
4658
4bbfe3dd2ab5
Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
81 log.Printf("info: loading mesh took %s\n", time.Since(start)) |
838
03e966b71a88
cross profile controller: Handle real errors before checking if there is no matching survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
834
diff
changeset
|
82 if err != nil { |
03e966b71a88
cross profile controller: Handle real errors before checking if there is no matching survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
834
diff
changeset
|
83 return |
03e966b71a88
cross profile controller: Handle real errors before checking if there is no matching survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
834
diff
changeset
|
84 } |
03e966b71a88
cross profile controller: Handle real errors before checking if there is no matching survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
834
diff
changeset
|
85 |
834
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
86 if tree == nil { |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
87 err = mw.JSONError{ |
834
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
88 Code: http.StatusNotFound, |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
89 Message: fmt.Sprintf("Cannot find survey for %s/%s.", |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
90 csi.Properties.Bottleneck, |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
91 csi.Properties.Date.Time), |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
92 } |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
93 return |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
94 } |
232f3f345cf0
Don't crash in cross profile controller if requesting a not existing survey.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
808
diff
changeset
|
95 |
4658
4bbfe3dd2ab5
Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
96 // The coordinate system of the mesh is an UTM projection. |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 // The input coordinates are in WGS84. |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 // So we need to reproject them. |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 start = time.Now() |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 |
762
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
102 var rp *models.Reprojector |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
103 if rp, err = models.NewReprojector( |
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:
1182
diff
changeset
|
104 ctx, conn, |
4658
4bbfe3dd2ab5
Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
105 models.WGS84, tree.EPSG(), |
762
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
106 ); err != nil { |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
107 return |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
108 } |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
109 defer rp.Close() |
01ba06da8f46
Factored repojection of coordinates to own logic as we need it to reproject the
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
761
diff
changeset
|
110 |
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:
1182
diff
changeset
|
111 coords, err := reproject(ctx, rp, csi.Geometry.Coordinates) |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
2547
5afca5bc1d7a
Cross profile endpoint: Normalized logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2319
diff
changeset
|
113 log.Printf("info: transforming input coords took %s\n", time.Since(start)) |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 if err != nil { |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 return |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
118 start = time.Now() |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
119 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
120 var segments mesh.MultiLineStringZ |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
121 |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 for i := 0; i < len(coords)-1; i++ { |
756
5e14000829d1
Complete vertical octree traversal. Seems not very selective.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
755
diff
changeset
|
123 c1 := &coords[i] |
5e14000829d1
Complete vertical octree traversal. Seems not very selective.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
755
diff
changeset
|
124 c2 := &coords[i+1] |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
125 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
126 verticalLine := mesh.NewVerticalLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon) |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
766
diff
changeset
|
127 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
128 var line mesh.MultiLineStringZ |
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4658
diff
changeset
|
129 tree.Vertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon, func(t *mesh.Triangle) { |
787
3d927e06b92c
Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
766
diff
changeset
|
130 if ls := verticalLine.Intersection(t); len(ls) > 0 { |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
131 line = append(line, ls) |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
132 } |
756
5e14000829d1
Complete vertical octree traversal. Seems not very selective.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
755
diff
changeset
|
133 }) |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
134 |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
135 if len(line) > 0 { |
2547
5afca5bc1d7a
Cross profile endpoint: Normalized logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2319
diff
changeset
|
136 log.Printf("info: line length: %d\n", len(line)) |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
137 // They are all on the segment (c1.Lat, c1.Lon) - (c2.Lat, c2.Lon). |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
138 // Sort them by project them on this line. |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
139 joined := line.JoinOnLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon) |
2547
5afca5bc1d7a
Cross profile endpoint: Normalized logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2319
diff
changeset
|
140 log.Printf("info: joined length: %d\n", len(joined)) |
796
0cc97135717c
More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
787
diff
changeset
|
141 segments = append(segments, joined...) |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
142 } |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
143 |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
144 } |
4658
4bbfe3dd2ab5
Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
145 log.Printf("info: mesh traversal took %s\n", time.Since(start)) |
766
afc635ab9f5b
Project the result data of the cross sections which are calculated in UTM back to WGS84.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
763
diff
changeset
|
146 |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
147 start = time.Now() |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
148 |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
149 var joined models.GeoJSONMultiLineCoordinatesZ |
1182
936dd3714325
cross sections: As the triangles in the octree are already clipped against the area
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
150 joined, err = projectBack( |
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:
1182
diff
changeset
|
151 ctx, |
4658
4bbfe3dd2ab5
Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4244
diff
changeset
|
152 segments, tree.EPSG(), |
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:
1182
diff
changeset
|
153 conn, |
808
e10a8a682297
Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
154 ) |
766
afc635ab9f5b
Project the result data of the cross sections which are calculated in UTM back to WGS84.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
763
diff
changeset
|
155 |
2547
5afca5bc1d7a
Cross profile endpoint: Normalized logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2319
diff
changeset
|
156 log.Printf("info: projecting back took %s\n", time.Since(start)) |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
157 if err != nil { |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
158 return |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
159 } |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
160 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
161 jr = mw.JSONResult{ |
763
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
162 Result: &models.CrossSectionOutput{ |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
163 Type: "Feature", |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
164 Geometry: models.CrossSectionOutputGeometry{ |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
165 Type: "MultiLineString", |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
166 Coordinates: joined, |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
167 }, |
d05bc3e34338
More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
762
diff
changeset
|
168 }, |
753
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 return |
e6f8d58434f4
Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 } |