comparison pkg/controllers/diff.go @ 4574:daed8a92024a iso-areas

Generate iso ares for sounding differences, too.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 07 Oct 2019 13:13:14 +0200
parents 4ca884dfc470
children c657dec6b0fa
comparison
equal deleted inserted replaced
4573:26e9846ed69f 4574:daed8a92024a
31 ) 31 )
32 32
33 const ( 33 const (
34 contourTolerance = 0.1 34 contourTolerance = 0.1
35 contourStep = 0.1 35 contourStep = 0.1
36 )
37
38 const (
39 // isoCellSize is the side length of a raster cell when tracing
40 // iso areas.
41 isoCellSize = 0.5
36 ) 42 )
37 43
38 const ( 44 const (
39 diffIDSQL = ` 45 diffIDSQL = `
40 SELECT sd.id FROM 46 SELECT sd.id FROM
78 ) 84 )
79 ), 85 ),
80 4326 86 4326
81 ) 87 )
82 ` 88 `
89 insertDiffIsoAreasQL = `
90 INSERT INTO caching.sounding_differences_iso_areas (
91 sounding_differences_id,
92 height,
93 areas
94 )
95 SELECT
96 $1,
97 $2,
98 ST_Transform(
99 ST_Multi(
100 ST_CollectionExtract(
101 ST_SimplifyPreserveTopology(
102 ST_Multi(ST_Collectionextract(
103 ST_MakeValid(ST_GeomFromWKB($4, $3::integer)), 3)),
104 $5
105 ),
106 3
107 )
108 ),
109 4326
110 )
111 `
83 ) 112 )
84 113
85 // Only allow three diffence calculation at once. 114 // Only allow three diffence calculation at once.
86 // TODO: Make this configurable? 115 // TODO: Make this configurable?
87 var diffCalculationSemaphore = semaphore.NewWeighted(int64(3)) 116 var diffCalculationSemaphore = semaphore.NewWeighted(int64(3))
277 if stmt, err = tx.PrepareContext(ctx, insertDiffContourSQL); err != nil { 306 if stmt, err = tx.PrepareContext(ctx, insertDiffContourSQL); err != nil {
278 return 307 return
279 } 308 }
280 defer stmt.Close() 309 defer stmt.Close()
281 310
311 var isoStmt *sql.Stmt
312 if isoStmt, err = tx.PrepareContext(ctx, insertDiffIsoAreasQL); err != nil {
313 return
314 }
315 defer isoStmt.Close()
316
282 if err = tx.QueryRowContext( 317 if err = tx.QueryRowContext(
283 ctx, 318 ctx,
284 insertDiffSQL, 319 insertDiffSQL,
285 dci.Bottleneck, 320 dci.Bottleneck,
286 dci.Minuend.Time, 321 dci.Minuend.Time,
302 id, 337 id,
303 ) 338 )
304 } 339 }
305 }) 340 })
306 341
342 areas := tree.TraceAreas(heights, isoCellSize)
343
344 for i, a := range areas {
345 if len(a) == 0 {
346 continue
347 }
348 if _, err = isoStmt.ExecContext(
349 ctx,
350 id, heights[i], minuendTree.EPSG,
351 a.AsWKB(),
352 contourTolerance,
353 ); err != nil {
354 return
355 }
356 }
357
307 log.Printf("info: calculating and storing iso lines took %v\n", 358 log.Printf("info: calculating and storing iso lines took %v\n",
308 time.Since(start)) 359 time.Since(start))
309 360
310 if err != nil { 361 if err != nil {
311 return 362 return