Mercurial > gemma
annotate pkg/wkb/data.go @ 5101:1b0b13e70bc1 queued-stage-done
Proxy the original job creator directly and not only the dependencies.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 24 Mar 2020 16:47:49 +0100 |
parents | 0ddb308fed37 |
children | 1222b777f51f |
rev | line source |
---|---|
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package wkb |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bytes" |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "encoding/binary" |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "fmt" |
4300
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
20 "math" |
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 ) |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 type ( |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 PointGeom struct { |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 X float64 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 Y float64 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 } |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 LinearRingGeom []PointGeom |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 PolygonGeom []LinearRingGeom |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 MultiPolygonGeom []PolygonGeom |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 ) |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
33 func (mpg MultiPolygonGeom) AsWKB() []byte { |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
34 |
4331
98497ac4af3c
Multi polygon: Fixed creation of WKB representation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
35 size := 1 + 4 + 4 |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
36 for _, pg := range mpg { |
4331
98497ac4af3c
Multi polygon: Fixed creation of WKB representation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
37 size += 1 + 4 + 4 |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
38 for _, r := range pg { |
4331
98497ac4af3c
Multi polygon: Fixed creation of WKB representation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
39 size += 4 + 2*8*len(r) |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
40 } |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
41 } |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
42 |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
43 buf := bytes.NewBuffer(make([]byte, 0, size)) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
44 |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
45 binary.Write(buf, binary.LittleEndian, NDR) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
46 binary.Write(buf, binary.LittleEndian, MultiPolygon) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
47 binary.Write(buf, binary.LittleEndian, uint32(len(mpg))) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
48 |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
49 for _, pg := range mpg { |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
50 binary.Write(buf, binary.LittleEndian, NDR) |
4331
98497ac4af3c
Multi polygon: Fixed creation of WKB representation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
51 binary.Write(buf, binary.LittleEndian, Polygon) |
4316
3d6a2c6b436c
shape upload stretch import: Store features in database. Still broken [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4314
diff
changeset
|
52 binary.Write(buf, binary.LittleEndian, uint32(len(pg))) |
4314
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
53 |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
54 for _, r := range pg { |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
55 binary.Write(buf, binary.LittleEndian, uint32(len(r))) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
56 for _, p := range r { |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
57 x := math.Float64bits(p.X) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
58 y := math.Float64bits(p.Y) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
59 binary.Write(buf, binary.LittleEndian, x) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
60 binary.Write(buf, binary.LittleEndian, y) |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
61 } |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
62 } |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
63 } |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
64 |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
65 return buf.Bytes() |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
66 } |
c3b5cf2f200a
shape upload stretch import: Converted multi polygon to WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4313
diff
changeset
|
67 |
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 func (mpg *MultiPolygonGeom) FromWKB(data []byte) error { |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 r := bytes.NewReader(data) |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 var order binary.ByteOrder |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
4300
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
73 switch endian, err := r.ReadByte(); { |
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 case err != nil: |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 return err |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 case endian == NDR: |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 order = binary.LittleEndian |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 case endian == XDR: |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 order = binary.BigEndian |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 default: |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 return fmt.Errorf("unknown byte order %x", endian) |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 } |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 var geomType uint32 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
4300
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
86 switch err := binary.Read(r, order, &geomType); { |
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 case err != nil: |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 return err |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 case geomType != MultiPolygon: |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 return fmt.Errorf("unknown geometry type %x", geomType) |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 |
4331
98497ac4af3c
Multi polygon: Fixed creation of WKB representation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4316
diff
changeset
|
93 var numPolygons uint32 |
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 if err := binary.Read(r, order, &numPolygons); err != nil { |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 return err |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 polygons := make([]PolygonGeom, numPolygons) |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
4300
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
100 for i := range polygons { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
101 switch endian, err := r.ReadByte(); { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
102 case err != nil: |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
103 return err |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
104 case endian == NDR: |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
105 order = binary.LittleEndian |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
106 case endian == XDR: |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
107 order = binary.BigEndian |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
108 default: |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
109 return fmt.Errorf("unknown byte order %x", endian) |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
110 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
111 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
112 switch err := binary.Read(r, order, &geomType); { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
113 case err != nil: |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
114 return err |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
115 case geomType != Polygon: |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
116 return fmt.Errorf("unknown geometry type %x", geomType) |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
117 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
118 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
119 var numRings uint32 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
120 if err := binary.Read(r, order, &numRings); err != nil { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
121 return err |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
122 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
123 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
124 rings := make([]LinearRingGeom, numRings) |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
125 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
126 for j := range rings { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
127 var numPoints uint32 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
128 if err := binary.Read(r, order, &numPoints); err != nil { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
129 return err |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
130 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
131 points := make([]PointGeom, numPoints) |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
132 |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
133 for k := range points { |
4301
b333d48ae555
Tightend the parsing of x/y data of WKB multi polyons a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4300
diff
changeset
|
134 var x, y uint64 |
4300
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
135 if err := binary.Read(r, order, &x); err != nil { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
136 return err |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
137 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
138 if err := binary.Read(r, order, &y); err != nil { |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
139 return err |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
140 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
141 points[k] = PointGeom{ |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
142 X: math.Float64frombits(x), |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
143 Y: math.Float64frombits(y), |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
144 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
145 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
146 rings[j] = points |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
147 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
148 polygons[i] = rings |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
149 } |
8b730ee6f17b
Completed parsing multi polygons from WKB.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4296
diff
changeset
|
150 |
4296
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 *mpg = polygons |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 return nil |
95786a675d70
WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
4313
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
154 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
155 func (lr LinearRingGeom) CCW() bool { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
156 var sum float64 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
157 for i, v1 := range lr { |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
158 v2 := lr[(i+1)%len(lr)] |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
159 sum += (v2.X - v1.X) * (v2.Y + v1.Y) |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
160 } |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
161 return sum > 0 |
5da02dcc51f6
shape upload stretch import: Started to decode geometries and attributes from uploaded shape file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4310
diff
changeset
|
162 } |
4667
0ddb308fed37
Reintroduced the ST_MakeValid calls when inserting the iso geometries into the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4331
diff
changeset
|
163 |
0ddb308fed37
Reintroduced the ST_MakeValid calls when inserting the iso geometries into the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4331
diff
changeset
|
164 func (lr LinearRingGeom) Reverse() { |
0ddb308fed37
Reintroduced the ST_MakeValid calls when inserting the iso geometries into the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4331
diff
changeset
|
165 for i, j := 0, len(lr)-1; i < j; i, j = i+1, j-1 { |
0ddb308fed37
Reintroduced the ST_MakeValid calls when inserting the iso geometries into the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4331
diff
changeset
|
166 lr[i], lr[j] = lr[j], lr[i] |
0ddb308fed37
Reintroduced the ST_MakeValid calls when inserting the iso geometries into the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4331
diff
changeset
|
167 } |
0ddb308fed37
Reintroduced the ST_MakeValid calls when inserting the iso geometries into the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4331
diff
changeset
|
168 } |