diff 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
line wrap: on
line diff
--- a/pkg/imports/wkb.go	Tue Sep 03 16:27:28 2019 +0200
+++ b/pkg/imports/wkb.go	Tue Sep 03 16:54:33 2019 +0200
@@ -55,6 +55,15 @@
 	return buf.Bytes()
 }
 
+func (ls lineSlice) LinearRingGeom() wkb.LinearRingGeom {
+	lr := make(wkb.LinearRingGeom, len(ls))
+	for i, v := range ls {
+		lr[i].X = v[0]
+		lr[i].Y = v[1]
+	}
+	return lr
+}
+
 func (p pointSlice) asWKB() []byte {
 
 	size := 1 + 4 + 2*8
@@ -147,3 +156,27 @@
 	}
 	return out
 }
+
+func (ps polygonSlice) MultiPolygonGeom() wkb.MultiPolygonGeom {
+
+	var mp wkb.MultiPolygonGeom
+	var curr wkb.PolygonGeom
+
+	for _, r := range ps {
+		lr := lineSlice(r).LinearRingGeom()
+		// A counter clockwise ring starts a new polygon.
+		if lr.CCW() {
+			if len(curr) > 0 {
+				mp = append(mp, curr)
+				curr = wkb.PolygonGeom{}
+			}
+		}
+		curr = append(curr, lr)
+	}
+
+	if len(curr) > 0 {
+		mp = append(mp, curr)
+	}
+
+	return mp
+}