comparison pkg/octree/polygon.go @ 4769:ea570f43d7a9 direct-diff

Loading of concrete clipping polygon is not needed any more.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Oct 2019 09:50:32 +0200
parents db6c2955ee31
children
comparison
equal deleted inserted replaced
4768:a2f16bbcc846 4769:ea570f43d7a9
13 13
14 package octree 14 package octree
15 15
16 import ( 16 import (
17 "bytes" 17 "bytes"
18 "context"
19 "database/sql"
20 "encoding/binary" 18 "encoding/binary"
21 "fmt" 19 "fmt"
22 "log" 20 "log"
23 "math" 21 "math"
24 "time"
25 22
26 "github.com/tidwall/rtree" 23 "github.com/tidwall/rtree"
27 24
28 "gemma.intevation.de/gemma/pkg/wkb" 25 "gemma.intevation.de/gemma/pkg/wkb"
29 ) 26 )
37 } 34 }
38 35
39 IntersectionType byte 36 IntersectionType byte
40 37
41 lineSegment []float64 38 lineSegment []float64
42 )
43
44 const (
45 clippingPolygonSQL = `
46 WITH joined AS (
47 SELECT
48 sr.area AS area,
49 sr.date_info AS date_info
50 FROM waterway.sounding_results sr
51 WHERE sr.bottleneck_id = $1
52 )
53 SELECT ST_AsBinary(
54 ST_Buffer(ST_intersection(
55 (SELECT ST_Transform(area::geometry, $2::int) FROM joined WHERE date_info = $3::date),
56 (SELECT ST_Transform(area::geometry, $2::int) FROM joined WHERE date_info = $4::date)
57 ), 0.1)
58 ) AS area
59 `
60 ) 39 )
61 40
62 const ( 41 const (
63 IntersectionInside IntersectionType = iota 42 IntersectionInside IntersectionType = iota
64 IntersectionOutSide 43 IntersectionOutSide
65 IntersectionOverlaps 44 IntersectionOverlaps
66 ) 45 )
67
68 func LoadClippingPolygon(
69 ctx context.Context,
70 conn *sql.Conn,
71 epsg uint32,
72 bottleneck string,
73 first, second time.Time,
74 ) (*Polygon, error) {
75
76 var clip []byte
77
78 if err := conn.QueryRowContext(
79 ctx, clippingPolygonSQL,
80 bottleneck,
81 epsg,
82 first, second,
83 ).Scan(&clip); err != nil {
84 return nil, err
85 }
86
87 var polygon Polygon
88 if err := polygon.FromWKB(clip); err != nil {
89 return nil, err
90 }
91 polygon.Indexify()
92 return &polygon, nil
93 }
94 46
95 func (ls lineSegment) Rect(interface{}) ([]float64, []float64) { 47 func (ls lineSegment) Rect(interface{}) ([]float64, []float64) {
96 48
97 var min, max [2]float64 49 var min, max [2]float64
98 50