Mercurial > gemma
annotate pkg/octree/tin.go @ 1528:5874cedd7f91
Sounding result import: Accept *.txt files for XYZ data, too.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 07 Dec 2018 12:21:55 +0100 |
parents | 84e78d2e2d95 |
children | de09bd3b5c05 |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
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:
971
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:
971
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
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:
971
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:
971
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
971
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:
971
diff
changeset
|
13 |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package octree |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bytes" |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
18 "context" |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
19 "database/sql" |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "encoding/binary" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "errors" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "fmt" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "io" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "log" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "math" |
1373
84e78d2e2d95
Backend: Centralized the definition of WGS84 constant in the models package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
26 |
84e78d2e2d95
Backend: Centralized the definition of WGS84 constant in the models package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/models" |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 var ( |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 errNoByteSlice = errors.New("Not a byte slice") |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 errTooLessPoints = errors.New("Too less points") |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 ) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 type Tin struct { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 EPSG uint32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 Vertices []Vertex |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 Triangles [][]int32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 Min Vertex |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 Max Vertex |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 func (t *Tin) FromWKB(data []byte) error { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 log.Printf("data length %d\n", len(data)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 r := bytes.NewReader(data) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 endian, err := r.ReadByte() |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 var order binary.ByteOrder |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 switch { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 case err != nil: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 case endian == wkbNDR: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 order = binary.LittleEndian |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 case endian == wkbXDR: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 order = binary.BigEndian |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 default: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 return fmt.Errorf("unknown byte order %x", endian) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 var geomType uint32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 err = binary.Read(r, order, &geomType) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 switch { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 case err != nil: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 case geomType != wkbTinZ: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 return fmt.Errorf("unknown geometry type %x", geomType) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 var num uint32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 if err = binary.Read(r, order, &num); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 vertices := make([]Vertex, 0, 100000) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 var v Vertex |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 v2i := make(map[Vertex]int32, 100000) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 var indexPool []int32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 allocIndices := func() []int32 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 if len(indexPool) == 0 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 indexPool = make([]int32, 3*8*1024) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 ids := indexPool[:3] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 indexPool = indexPool[3:] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 return ids |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 var triangles [][]int32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64} |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 max := Vertex{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64} |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 for i := uint32(0); i < num; i++ { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 endian, err = r.ReadByte() |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 switch { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 case err != nil: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 case endian == wkbNDR: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 order = binary.LittleEndian |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 case endian == wkbXDR: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 order = binary.BigEndian |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 default: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 return fmt.Errorf("unknown byte order %x", endian) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 err = binary.Read(r, order, &geomType) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 switch { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 case err != nil: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 case geomType != wkbTriangleZ: |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 return fmt.Errorf("unknown geometry type %d", geomType) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 var rings uint32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 if err = binary.Read(r, order, &rings); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 triangle := allocIndices() |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 for ring := uint32(0); ring < rings; ring++ { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 var npoints uint32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 if err = binary.Read(r, order, &npoints); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 if npoints < 3 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 return errTooLessPoints |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 for p := uint32(0); p < npoints; p++ { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 var x, y, z uint64 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 for _, addr := range []*uint64{&x, &y, &z} { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if err = binary.Read(r, order, addr); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 if p >= 3 || ring >= 1 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 // Don't store the forth point. |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 continue |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 // Do this conversion later to spare reflect calls |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 // and allocs in binary.Read. |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 v.X = math.Float64frombits(x) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 v.Y = math.Float64frombits(y) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 v.Z = math.Float64frombits(z) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 idx, found := v2i[v] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 if !found { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 idx = int32(len(vertices)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 v2i[v] = idx |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 vertices = append(vertices, v) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 min.Minimize(v) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 max.Maximize(v) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 triangle[p] = idx |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 triangles = append(triangles, triangle) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 log.Printf("bbox: [[%f, %f], [%f, %f]]\n", |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 min.X, min.Y, max.X, max.Y) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 *t = Tin{ |
1373
84e78d2e2d95
Backend: Centralized the definition of WGS84 constant in the models package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
173 EPSG: models.WGS84, |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 Vertices: vertices, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 Triangles: triangles, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 Min: min, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 Max: max, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 return nil |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
183 const ( |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
184 tinSQLPrefix = `WITH trans AS ( |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
185 SELECT |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
186 ST_Buffer(ST_Transform(area::geometry, $1::int), 0.001) AS area, |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
187 ST_Transform(point_cloud::geometry, $1::int) AS point_cloud |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
188 FROM waterway.sounding_results |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
189 ` |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
190 tinSQLSuffix = ` |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
191 ), |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
192 triangles AS ( |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
193 SELECT t.geom AS geom, ST_MakePolygon(ST_ExteriorRing(t.geom)) AS poly FROM ( |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
194 SELECT (ST_Dump( |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
195 ST_DelaunayTriangles(point_cloud, 0, 2))).geom |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
196 FROM trans) t |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
197 ) |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
198 SELECT ST_AsBinary(ST_Collect(triangles.geom)) FROM triangles, trans |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
199 WHERE ST_Covers(trans.area, triangles.poly)` |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
200 |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
201 loadTinByIDSQL = tinSQLPrefix + `WHERE id = $2` + tinSQLSuffix |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
202 ) |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
203 |
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:
1017
diff
changeset
|
204 func GenerateTinByID( |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
205 ctx context.Context, |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
206 conn *sql.Conn, |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
207 id int64, |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
208 epsg uint32, |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
209 ) (*Tin, error) { |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
210 var tin Tin |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
211 err := conn.QueryRowContext(ctx, loadTinByIDSQL, epsg, id).Scan(&tin) |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
212 switch { |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
213 case err == sql.ErrNoRows: |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
214 return nil, nil |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
215 case err != nil: |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
216 return nil, err |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
217 } |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
218 tin.EPSG = epsg |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
219 return &tin, nil |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
220 } |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
221 |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 func (t *Tin) Scan(raw interface{}) error { |
971
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
223 if raw == nil { |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
224 return nil |
f9fb6c399f3f
Moved generating of tins to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
225 } |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 data, ok := raw.([]byte) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 if !ok { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 return errNoByteSlice |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 return t.FromWKB(data) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 func (t *Tin) Serialize(w io.Writer) error { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 if err := binary.Write(w, binary.LittleEndian, t.EPSG); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 if err := t.Min.Write(w); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 if err := t.Max.Write(w); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 if err := binary.Write( |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 w, binary.LittleEndian, uint32(len(t.Vertices))); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 for _, v := range t.Vertices { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 if err := v.Write(w); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 log.Printf("vertices %d (%d)\n", len(t.Vertices), len(t.Vertices)*3*8) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 if err := binary.Write( |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 w, binary.LittleEndian, uint32(len(t.Triangles))); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 var buf [binary.MaxVarintLen32]byte |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 var written int |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 var last int32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 for _, triangle := range t.Triangles { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 for _, idx := range triangle { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 value := idx - last |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 n := binary.PutVarint(buf[:], int64(value)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 for p := buf[:n]; len(p) > 0; p = p[n:] { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 var err error |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 if n, err = w.Write(p); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 written += n |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 last = idx |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 log.Printf("compressed tin indices in bytes: %d (%d)\n", |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 written, 3*4*len(t.Triangles)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 return nil |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 } |