comparison pkg/imports/wkb.go @ 1860:f54ac71db1ac

Importer: Added point geoemtry to wkb datatypes.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 17 Jan 2019 13:14:32 +0100
parents 09349ca27dd7
children 63475c8e710e
comparison
equal deleted inserted replaced
1859:9780cb4ef6a6 1860:f54ac71db1ac
21 21
22 shp "github.com/jonas-p/go-shp" 22 shp "github.com/jonas-p/go-shp"
23 ) 23 )
24 24
25 type ( 25 type (
26 pointSlice []float64
26 lineSlice [][]float64 27 lineSlice [][]float64
27 polygonSlice [][][]float64 28 polygonSlice [][][]float64
28 ) 29 )
29 30
30 const ( 31 const (
31 wkbNDR byte = 1 32 wkbNDR byte = 1
32 33
34 wkbPoint uint32 = 1
33 wkbLineString uint32 = 2 35 wkbLineString uint32 = 2
34 wkbPolygon uint32 = 3 36 wkbPolygon uint32 = 3
35 ) 37 )
36 38
37 func (l lineSlice) asWKB() []byte { 39 func (l lineSlice) asWKB() []byte {
53 lon = c[1] 55 lon = c[1]
54 } 56 }
55 binary.Write(buf, binary.LittleEndian, math.Float64bits(lat)) 57 binary.Write(buf, binary.LittleEndian, math.Float64bits(lat))
56 binary.Write(buf, binary.LittleEndian, math.Float64bits(lon)) 58 binary.Write(buf, binary.LittleEndian, math.Float64bits(lon))
57 } 59 }
60
61 return buf.Bytes()
62 }
63
64 func (p pointSlice) asWKB() []byte {
65
66 size := 1 + 4 + 2*8
67
68 buf := bytes.NewBuffer(make([]byte, 0, size))
69
70 binary.Write(buf, binary.LittleEndian, wkbNDR)
71 binary.Write(buf, binary.LittleEndian, wkbPoint)
72
73 var lat, lon float64
74 if len(p) > 0 {
75 lat = p[0]
76 }
77 if len(p) > 1 {
78 lon = p[1]
79 }
80 binary.Write(buf, binary.LittleEndian, math.Float64bits(lat))
81 binary.Write(buf, binary.LittleEndian, math.Float64bits(lon))
58 82
59 return buf.Bytes() 83 return buf.Bytes()
60 } 84 }
61 85
62 func (p polygonSlice) asWKB() []byte { 86 func (p polygonSlice) asWKB() []byte {