changeset 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 9780cb4ef6a6
children 5083a1d19a4b
files pkg/imports/wkb.go
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/wkb.go	Thu Jan 17 13:12:37 2019 +0100
+++ b/pkg/imports/wkb.go	Thu Jan 17 13:14:32 2019 +0100
@@ -23,6 +23,7 @@
 )
 
 type (
+	pointSlice   []float64
 	lineSlice    [][]float64
 	polygonSlice [][][]float64
 )
@@ -30,6 +31,7 @@
 const (
 	wkbNDR byte = 1
 
+	wkbPoint      uint32 = 1
 	wkbLineString uint32 = 2
 	wkbPolygon    uint32 = 3
 )
@@ -59,6 +61,28 @@
 	return buf.Bytes()
 }
 
+func (p pointSlice) asWKB() []byte {
+
+	size := 1 + 4 + 2*8
+
+	buf := bytes.NewBuffer(make([]byte, 0, size))
+
+	binary.Write(buf, binary.LittleEndian, wkbNDR)
+	binary.Write(buf, binary.LittleEndian, wkbPoint)
+
+	var lat, lon float64
+	if len(p) > 0 {
+		lat = p[0]
+	}
+	if len(p) > 1 {
+		lon = p[1]
+	}
+	binary.Write(buf, binary.LittleEndian, math.Float64bits(lat))
+	binary.Write(buf, binary.LittleEndian, math.Float64bits(lon))
+
+	return buf.Bytes()
+}
+
 func (p polygonSlice) asWKB() []byte {
 	if p == nil {
 		return nil