annotate pkg/imports/wkb.go @ 4313:5da02dcc51f6

shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Sep 2019 16:54:33 +0200
parents 8b75ac5e243e
children 046a07a33b19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 //
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 //
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 //
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 package imports
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16 import (
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 "bytes"
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18 "encoding/binary"
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 "fmt"
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 "math"
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 shp "github.com/jonas-p/go-shp"
2471
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
23
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
24 "gemma.intevation.de/gemma/pkg/wkb"
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 )
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 type (
1860
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
28 pointSlice []float64
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 lineSlice [][]float64
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 polygonSlice [][][]float64
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 )
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 func (l lineSlice) asWKB() []byte {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 size := 1 + 4 + 4 + len(l)*(2*8)
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 buf := bytes.NewBuffer(make([]byte, 0, size))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38
2471
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
39 binary.Write(buf, binary.LittleEndian, wkb.NDR)
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
40 binary.Write(buf, binary.LittleEndian, wkb.LineString)
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 binary.Write(buf, binary.LittleEndian, uint32(len(l)))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 for _, c := range l {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 var lat, lon float64
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 if len(c) > 0 {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 lat = c[0]
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 if len(c) > 1 {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 lon = c[1]
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51 binary.Write(buf, binary.LittleEndian, math.Float64bits(lat))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 binary.Write(buf, binary.LittleEndian, math.Float64bits(lon))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 return buf.Bytes()
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57
4313
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
58 func (ls lineSlice) LinearRingGeom() wkb.LinearRingGeom {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
59 lr := make(wkb.LinearRingGeom, len(ls))
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
60 for i, v := range ls {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
61 lr[i].X = v[0]
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
62 lr[i].Y = v[1]
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
63 }
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
64 return lr
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
65 }
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
66
1860
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
67 func (p pointSlice) asWKB() []byte {
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
68
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
69 size := 1 + 4 + 2*8
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
70
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
71 buf := bytes.NewBuffer(make([]byte, 0, size))
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
72
2471
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
73 binary.Write(buf, binary.LittleEndian, wkb.NDR)
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
74 binary.Write(buf, binary.LittleEndian, wkb.Point)
1860
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
75
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
76 var lat, lon float64
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
77 if len(p) > 0 {
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
78 lat = p[0]
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
79 }
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
80 if len(p) > 1 {
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
81 lon = p[1]
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
82 }
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
83 binary.Write(buf, binary.LittleEndian, math.Float64bits(lat))
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
84 binary.Write(buf, binary.LittleEndian, math.Float64bits(lon))
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
85
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
86 return buf.Bytes()
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
87 }
f54ac71db1ac Importer: Added point geoemtry to wkb datatypes.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1786
diff changeset
88
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 func (p polygonSlice) asWKB() []byte {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90 if p == nil {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91 return nil
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93 // pre-calculate size to avoid reallocations.
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 size := 1 + 4 + 4
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95 for _, ring := range p {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96 size += 4 + len(ring)*2*8
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
98
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
99 buf := bytes.NewBuffer(make([]byte, 0, size))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100
2471
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
101 binary.Write(buf, binary.LittleEndian, wkb.NDR)
63475c8e710e Moved WKB constants to own package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1860
diff changeset
102 binary.Write(buf, binary.LittleEndian, wkb.Polygon)
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103 binary.Write(buf, binary.LittleEndian, uint32(len(p)))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
105 for _, ring := range p {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106 binary.Write(buf, binary.LittleEndian, uint32(len(ring)))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
107 for _, v := range ring {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108 var lat, lon float64
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 if len(v) > 0 {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
110 lat = v[0]
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 if len(v) > 1 {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
113 lon = v[1]
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
114 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
115 binary.Write(buf, binary.LittleEndian, math.Float64bits(lat))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
116 binary.Write(buf, binary.LittleEndian, math.Float64bits(lon))
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
117 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
118 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
119
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
120 return buf.Bytes()
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
121 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
122
1786
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
123 func shapeToPolygon(s shp.Shape) (polygonSlice, error) {
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
124 switch p := s.(type) {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
125 case *shp.Polygon:
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
126 return toPolygon(p.NumParts, p.Parts, p.Points), nil
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
127 case *shp.PolygonZ:
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
128 return toPolygon(p.NumParts, p.Parts, p.Points), nil
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
129 case *shp.PolygonM:
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
130 return toPolygon(p.NumParts, p.Parts, p.Points), nil
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
131 }
4177
8b75ac5e243e Made 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2471
diff changeset
132 return nil, fmt.Errorf("unsupported shape type %T", s)
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
133 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
134
1786
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
135 func toPolygon(numParts int32, parts []int32, points []shp.Point) polygonSlice {
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
136 out := make(polygonSlice, numParts)
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
137 var pos int32
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
138
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
139 for i := range out {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
140 var howMany int32
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
141 if i+1 >= len(parts) {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
142 howMany = int32(len(points)) - pos
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
143 } else {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
144 howMany = parts[i+1] - parts[i]
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
145 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
146
1786
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
147 line := make([][]float64, howMany)
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
148 vertices := make([]float64, 2*howMany)
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
149 for j := int32(0); j < howMany; j, pos = j+1, pos+1 {
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
150 p := &points[pos]
1786
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
151 vertex := vertices[j*2 : j*2+2]
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
152 vertex[0], vertex[1] = p.X, p.Y
09349ca27dd7 Imports: Removed duplicated code path to store WKB polygons into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1785
diff changeset
153 line[j] = vertex
1785
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
154 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
155 out[i] = line
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
156 }
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
157 return out
614c6c766691 Waterway area import: Implemented.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
158 }
4313
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
159
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
160 func (ps polygonSlice) MultiPolygonGeom() wkb.MultiPolygonGeom {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
161
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
162 var mp wkb.MultiPolygonGeom
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
163 var curr wkb.PolygonGeom
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
164
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
165 for _, r := range ps {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
166 lr := lineSlice(r).LinearRingGeom()
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
167 // A counter clockwise ring starts a new polygon.
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
168 if lr.CCW() {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
169 if len(curr) > 0 {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
170 mp = append(mp, curr)
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
171 curr = wkb.PolygonGeom{}
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
172 }
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
173 }
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
174 curr = append(curr, lr)
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
175 }
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
176
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
177 if len(curr) > 0 {
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
178 mp = append(mp, curr)
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
179 }
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
180
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
181 return mp
5da02dcc51f6 shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4177
diff changeset
182 }