comparison pkg/controllers/cross.go @ 1182:936dd3714325

cross sections: As the triangles in the octree are already clipped against the area of the soundind result there is no need to clip the cross section result against this area.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 15 Nov 2018 15:50:02 +0100
parents a244b18cb916
children d753ce6cf588
comparison
equal deleted inserted replaced
1181:1335e088e7ef 1182:936dd3714325
43 } 43 }
44 } 44 }
45 return dst, nil 45 return dst, nil
46 } 46 }
47 47
48 const projectBackSQL = `
49 SELECT ST_AsBinary(
50 ST_Transform(ST_GeomFromWKB($2, $1::integer), 4326))`
51
48 func projectBack( 52 func projectBack(
49 rp *models.Reprojector,
50 lines octree.MultiLineStringZ,
51 ctx context.Context,
52 ) (models.GeoJSONMultiLineCoordinatesZ, error) {
53
54 out := make(models.GeoJSONMultiLineCoordinatesZ, len(lines))
55
56 for i, segment := range lines {
57
58 coords := make(models.GeoJSONLineCoordinatesZ, len(segment))
59 out[i] = coords
60 for j, v := range segment {
61 lat, lon, err := rp.Reproject(v.X, v.Y, ctx)
62 if err != nil {
63 return nil, err
64 }
65 coords[j] = models.GeoJSONCoordinateZ{Lat: lat, Lon: lon, Z: v.Z}
66 }
67 }
68 return out, nil
69 }
70
71 const clipSQL = `
72 SELECT ST_AsBinary(ST_Transform(ST_Multi(ST_Intersection(
73 ST_Transform(area::geometry, $1::integer),
74 ST_GeomFromWKB($2, $1::integer))), 4326))
75 FROM waterway.sounding_results
76 WHERE bottleneck_id = $3 AND date_info = $4::date`
77
78 func clipAgainstArea(
79 line octree.MultiLineStringZ, 53 line octree.MultiLineStringZ,
80 epsg uint32, 54 epsg uint32,
81 bottleneck string,
82 dateInfo time.Time,
83 conn *sql.Conn, 55 conn *sql.Conn,
84 ctx context.Context, 56 ctx context.Context,
85 ) (models.GeoJSONMultiLineCoordinatesZ, error) { 57 ) (models.GeoJSONMultiLineCoordinatesZ, error) {
86 58
87 var mls models.GeoJSONMultiLineCoordinatesZ 59 var mls models.GeoJSONMultiLineCoordinatesZ
88 err := conn.QueryRowContext( 60 err := conn.QueryRowContext(
89 ctx, clipSQL, 61 ctx, projectBackSQL,
90 epsg, line.AsWKB(), 62 epsg, line.AsWKB(),
91 bottleneck, dateInfo,
92 ).Scan(&mls) 63 ).Scan(&mls)
93 64
94 return mls, err 65 return mls, err
95 } 66 }
96 67
175 log.Printf("octree traversal took: %s\n", time.Since(start)) 146 log.Printf("octree traversal took: %s\n", time.Since(start))
176 147
177 start = time.Now() 148 start = time.Now()
178 149
179 var joined models.GeoJSONMultiLineCoordinatesZ 150 var joined models.GeoJSONMultiLineCoordinatesZ
180 joined, err = clipAgainstArea( 151 joined, err = projectBack(
181 segments, tree.EPSG, 152 segments, tree.EPSG,
182 csi.Properties.Bottleneck, csi.Properties.Date.Time,
183 conn, req.Context(), 153 conn, req.Context(),
184 ) 154 )
185 155
186 log.Printf("clipping and projecting back took: %s\n", time.Since(start)) 156 log.Printf("projecting back took: %s\n", time.Since(start))
187 if err != nil { 157 if err != nil {
188 return 158 return
189 } 159 }
190 160
191 jr = JSONResult{ 161 jr = JSONResult{