annotate pkg/controllers/cross.go @ 935:430d52c2f6ef

client: move layer isolines to be drawn at the top * Move layer isolones to be drawn last (and thus being "on top") so that the bottleneck (position) layer will not interfere that much with the colours. It also allows to set a white background with high opacity on the bottleneck polygon in order to get highly visible isolines.
author Bernhard Reiter <bernhard@intevation.de>
date Mon, 08 Oct 2018 17:20:42 +0200
parents 03e966b71a88
children a244b18cb916
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package controllers
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import (
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 "context"
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 "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
6 "fmt"
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 "log"
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 "net/http"
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 "time"
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 "gemma.intevation.de/gemma/pkg/models"
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 "gemma.intevation.de/gemma/pkg/octree"
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 )
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
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
15 const WGS84 = 4326
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
16
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 func reproject(
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
18 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
19 src models.GeoJSONLineCoordinates,
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 ctx context.Context,
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 ) (models.GeoJSONLineCoordinates, error) {
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 dst := make(models.GeoJSONLineCoordinates, len(src))
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 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
25 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
26 if dst[i].Lat, dst[i].Lon, err = rp.Reproject(
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
27 s.Lat, s.Lon, ctx,
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
28 ); err != nil {
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 return nil, err
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 }
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 return dst, nil
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
35 func projectBack(
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
36 rp *models.Reprojector,
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
37 lines octree.MultiLineStringZ,
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
38 ctx context.Context,
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
39 ) (models.GeoJSONMultiLineCoordinatesZ, error) {
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
40
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
41 out := make(models.GeoJSONMultiLineCoordinatesZ, len(lines))
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
42
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
43 for i, segment := range lines {
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
44
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
45 coords := make(models.GeoJSONLineCoordinatesZ, len(segment))
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
46 out[i] = coords
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
47 for j, v := range segment {
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
48 lat, lon, err := rp.Reproject(v.X, v.Y, ctx)
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
49 if err != nil {
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
50 return nil, err
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
51 }
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 coords[j] = models.GeoJSONCoordinateZ{Lat: lat, Lon: lon, Z: v.Z}
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
53 }
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
54 }
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
55 return out, nil
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
56 }
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
57
808
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
58 const clipSQL = `
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
59 SELECT ST_AsBinary(ST_Transform(ST_Multi(ST_Intersection(
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
60 ST_Transform(area::geometry, $1::integer),
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
61 ST_GeomFromWKB($2, $1::integer))), 4326))
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
62 FROM waterway.sounding_results
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
63 WHERE bottleneck_id = $3 AND date_info = $4::date`
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
64
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
65 func clipAgainstArea(
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
66 line octree.MultiLineStringZ,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
67 epsg uint32,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
68 bottleneck string,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
69 dateInfo time.Time,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
70 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
71 ctx context.Context,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
72 ) (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
73
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
74 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
75 err := conn.QueryRowContext(
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
76 ctx, clipSQL,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
77 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
78 bottleneck, dateInfo,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
79 ).Scan(&mls)
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
80
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
81 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
82 }
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
83
801
b6a1779ffb42 Removed old cross section controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 796
diff changeset
84 func crossSection(
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 input interface{},
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 req *http.Request,
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 conn *sql.Conn,
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 ) (jr JSONResult, err error) {
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 csi := input.(*models.CrossSectionInput)
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 start := time.Now()
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 tree, err := octree.Cache.Get(
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 csi.Properties.Bottleneck, csi.Properties.Date.Time,
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 conn, req.Context())
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97
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
98 log.Printf("loading octree took: %s\n", time.Since(start))
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
99 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
100 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
101 }
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
102
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
103 if tree == nil {
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
104 err = JSONError{
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
105 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
106 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
107 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
108 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
109 }
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
110 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
111 }
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
112
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 // The coordinate system of the octree is an UTM projection.
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 // The input coordinates are in WGS84.
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 // So we need to reproject them.
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 start = time.Now()
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118
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
119 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
120 if rp, err = models.NewReprojector(
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 conn, req.Context(),
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
122 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
123 ); 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
124 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
125 }
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
126 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
127
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
128 coords, err := reproject(rp, csi.Geometry.Coordinates, req.Context())
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 log.Printf("transforming input coords took: %s\n", time.Since(start))
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 if err != nil {
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 return
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 }
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
135 start = time.Now()
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
136
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
137 var segments octree.MultiLineStringZ
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
138
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 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
140 c1 := &coords[i]
5e14000829d1 Complete vertical octree traversal. Seems not very selective.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 755
diff changeset
141 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
142
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 766
diff changeset
143 verticalLine := octree.NewVerticalLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon)
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 766
diff changeset
144
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
145 var line octree.MultiLineStringZ
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
146 tree.Vertical(c1.Lat, c1.Lon, c2.Lat, c2.Lon, func(t *octree.Triangle) {
787
3d927e06b92c Triangle intersection. WIP. Currently interpolation is messed up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 766
diff changeset
147 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
148 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
149 }
756
5e14000829d1 Complete vertical octree traversal. Seems not very selective.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 755
diff changeset
150 })
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
151
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
152 if len(line) > 0 {
796
0cc97135717c More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
153 log.Printf("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
154 // 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
155 // 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
156 joined := line.JoinOnLine(c1.Lat, c1.Lon, c2.Lat, c2.Lon)
0cc97135717c More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
157 log.Printf("joined length: %d\n", len(joined))
0cc97135717c More fixes to vertical triangle intersection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
158 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
159 }
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
160
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
161 }
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
162 log.Printf("octree 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
163
763
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
164 start = time.Now()
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
165
808
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
166 var joined models.GeoJSONMultiLineCoordinatesZ
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
167 joined, err = clipAgainstArea(
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
168 segments, tree.EPSG,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
169 csi.Properties.Bottleneck, csi.Properties.Date.Time,
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
170 conn, req.Context(),
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
171 )
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
172
808
e10a8a682297 Cross sections: Clip result against area of the sounding result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
173 log.Printf("clipping and 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
174 if err != nil {
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
175 return
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
176 }
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
177
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
178 jr = JSONResult{
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
179 Result: &models.CrossSectionOutput{
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
180 Type: "Feature",
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
181 Geometry: models.CrossSectionOutputGeometry{
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
182 Type: "MultiLineString",
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
183 Coordinates: joined,
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
184 },
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
185 Properties: map[string]interface{}{},
d05bc3e34338 More infrastructure for the octree driven cross section endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 762
diff changeset
186 },
753
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 }
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 return
e6f8d58434f4 Added stub for octree based cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 }