changeset 5007:799e8248de8d

First step to move geometry creation for WFS features to loader.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 11 Mar 2020 14:23:52 +0100
parents 5269fd823ca7
children 0b97f5301a17
files pkg/imports/fm.go pkg/imports/wfsjob.go pkg/imports/wkb.go
diffstat 3 files changed, 32 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/fm.go	Wed Mar 11 11:35:23 2020 +0100
+++ b/pkg/imports/fm.go	Wed Mar 11 14:23:52 2020 +0100
@@ -219,7 +219,7 @@
 				),
 				consume,
 				createInvalidation("bcnlat_hydro"),
-				newPointSlice(func() interface{} { return new(bcnlatHydroProperties) }),
+				newPointFeature(func() interface{} { return new(bcnlatHydroProperties) }),
 			),
 		})
 
@@ -235,7 +235,7 @@
 				),
 				consume,
 				createInvalidation("bcnlat_ienc"),
-				newPointSlice(func() interface{} { return new(bcnlatIencProperties) }),
+				newPointFeature(func() interface{} { return new(bcnlatIencProperties) }),
 			),
 		})
 
@@ -251,7 +251,7 @@
 				),
 				consume,
 				createInvalidation("boylat_hydro"),
-				newPointSlice(func() interface{} { return new(boylatHydroProperties) }),
+				newPointFeature(func() interface{} { return new(boylatHydroProperties) }),
 			),
 		})
 
@@ -267,7 +267,7 @@
 				),
 				consume,
 				createInvalidation("boylat_ienc"),
-				newPointSlice(func() interface{} { return new(boylatIencProperties) }),
+				newPointFeature(func() interface{} { return new(boylatIencProperties) }),
 			),
 		})
 
@@ -283,7 +283,7 @@
 				),
 				consume,
 				createInvalidation("boycar"),
-				newPointSlice(func() interface{} { return new(boycarProperties) }),
+				newPointFeature(func() interface{} { return new(boycarProperties) }),
 			),
 		})
 
@@ -298,7 +298,7 @@
 				),
 				consume,
 				createInvalidation("boysaw"),
-				newPointSlice(func() interface{} { return new(boysawProperties) }),
+				newPointFeature(func() interface{} { return new(boysawProperties) }),
 			),
 		})
 
@@ -314,7 +314,7 @@
 				),
 				consume,
 				createInvalidation("boyspp"),
-				newPointSlice(func() interface{} { return new(boysppProperties) }),
+				newPointFeature(func() interface{} { return new(boysppProperties) }),
 			),
 		})
 
@@ -329,7 +329,7 @@
 				),
 				consume,
 				createInvalidation("daymar_hydro"),
-				newPointSlice(func() interface{} { return new(daymarHydroProperties) }),
+				newPointFeature(func() interface{} { return new(daymarHydroProperties) }),
 			),
 		})
 
@@ -345,7 +345,7 @@
 				),
 				consume,
 				createInvalidation("daymar_ienc"),
-				newPointSlice(func() interface{} { return new(daymarIencProperties) }),
+				newPointFeature(func() interface{} { return new(daymarIencProperties) }),
 			),
 		})
 
@@ -364,7 +364,7 @@
 				),
 				consume,
 				createInvalidation("lights"),
-				newPointSlice(func() interface{} { return new(lightsProperties) }),
+				newPointFeature(func() interface{} { return new(lightsProperties) }),
 			),
 		})
 
@@ -383,7 +383,7 @@
 				),
 				consume,
 				createInvalidation("notmrk"),
-				newPointSlice(func() interface{} { return new(notmrkProperties) }),
+				newPointFeature(func() interface{} { return new(notmrkProperties) }),
 			),
 		})
 
@@ -398,7 +398,7 @@
 				),
 				consume,
 				createInvalidation("rtpbcn"),
-				newPointSlice(func() interface{} { return new(rtpbcnProperties) }),
+				newPointFeature(func() interface{} { return new(rtpbcnProperties) }),
 			),
 		})
 
@@ -413,7 +413,7 @@
 				),
 				consume,
 				createInvalidation("topmar"),
-				newPointSlice(func() interface{} { return new(topmarProperties) }),
+				newPointFeature(func() interface{} { return new(topmarProperties) }),
 			),
 		})
 }
--- a/pkg/imports/wfsjob.go	Wed Mar 11 11:35:23 2020 +0100
+++ b/pkg/imports/wfsjob.go	Wed Mar 11 14:23:52 2020 +0100
@@ -38,7 +38,7 @@
 		Commit() error
 		Rollback() error
 
-		NewFeature() (kind string, geom interface{}, properties interface{})
+		NewFeature() (kind string, properties interface{})
 
 		Consume(geom, properties interface{}, epsg int) error
 	}
@@ -58,6 +58,10 @@
 	}
 )
 
+var kindToGeometry = map[string]func() interface{}{
+	"Point": func() interface{} { return new(pointSlice) },
+}
+
 func (wfjc *WFSFeatureJobCreator) Description() string {
 	return wfjc.description
 }
@@ -176,7 +180,15 @@
 				continue
 			}
 
-			kind, geom, props := consumer.NewFeature()
+			kind, props := consumer.NewFeature()
+
+			makeGeom := kindToGeometry[kind]
+			if makeGeom == nil {
+				unsupported[kind]++
+				continue
+			}
+
+			geom := makeGeom()
 
 			if err := json.Unmarshal(*feature.Properties, props); err != nil {
 				badProperties++
@@ -251,7 +263,7 @@
 		tx         *sql.Tx
 		feedback   Feedback
 		consume    func(*SQLGeometryConsumer, interface{}, interface{}, int) error
-		newFeature func() (string, interface{}, interface{})
+		newFeature func() (string, interface{})
 		preCommit  func(*SQLGeometryConsumer) error
 		savepoint  func(func() error) error
 		stmts      []*sql.Stmt
@@ -285,7 +297,7 @@
 	return err
 }
 
-func (sgc *SQLGeometryConsumer) NewFeature() (string, interface{}, interface{}) {
+func (sgc *SQLGeometryConsumer) NewFeature() (string, interface{}) {
 	return sgc.newFeature()
 }
 
@@ -308,7 +320,7 @@
 	init func(*SQLGeometryConsumer) error,
 	consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error,
 	preCommit func(*SQLGeometryConsumer) error,
-	newFeature func() (string, interface{}, interface{}),
+	newFeature func() (string, interface{}),
 
 ) func(context.Context, *sql.Conn, Feedback) (WFSFeatureConsumer, error) {
 	return func(ctx context.Context, conn *sql.Conn, feedback Feedback) (WFSFeatureConsumer, error) {
--- a/pkg/imports/wkb.go	Wed Mar 11 11:35:23 2020 +0100
+++ b/pkg/imports/wkb.go	Wed Mar 11 14:23:52 2020 +0100
@@ -30,10 +30,8 @@
 	polygonSlice [][][]float64
 )
 
-func newPointSlice(newProperties func() interface{}) func() (string, interface{}, interface{}) {
-	return func() (string, interface{}, interface{}) {
-		return "Point", new(pointSlice), newProperties()
-	}
+func newPointFeature(newProperties func() interface{}) func() (string, interface{}) {
+	return func() (string, interface{}) { return "Point", newProperties() }
 }
 
 func (ls lineSlice) asWKB() []byte {