annotate pkg/wkb/data.go @ 4296:95786a675d70

WIP: Started with downloading stretches as ESRI shapes. GET /api/data/stretch/shape/{stretch}
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 30 Aug 2019 18:34:27 +0200
parents
children 8b730ee6f17b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "log"
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
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 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
34 r := bytes.NewReader(data)
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 endian, err := r.ReadByte()
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 var order binary.ByteOrder
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 switch {
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 case err != nil:
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 return err
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 case endian == NDR:
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 order = binary.LittleEndian
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 case endian == XDR:
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 order = binary.BigEndian
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 default:
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 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
49 }
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 var geomType uint32
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 err = binary.Read(r, order, &geomType)
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 switch {
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 case err != nil:
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 return err
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 case geomType != MultiPolygon:
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 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
59 }
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 var numPolygons int32
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 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
63 return err
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 log.Printf("info: num polygons: %d\n", numPolygons)
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 polygons := make([]PolygonGeom, numPolygons)
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 // TODO: Parse the polygons.
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 *mpg = polygons
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 return nil
95786a675d70 WIP: Started with downloading stretches as ESRI shapes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 }