diff pkg/imports/fm.go @ 4977:4bf6cde2d996

Generalize WFS point import job to be able to import other geometry types, too.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Mar 2020 18:05:33 +0100
parents e1d8217954a0
children 35a3dc12050f
line wrap: on
line diff
--- a/pkg/imports/fm.go	Tue Mar 03 15:33:04 2020 +0100
+++ b/pkg/imports/fm.go	Tue Mar 03 18:05:33 2020 +0100
@@ -209,7 +209,7 @@
 
 func init() {
 	RegisterJobCreator(BCNLATHYDROJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks bcnlat (HYDRO)",
 			depends:     [2][]string{{"fairway_marks_bcnlat_hydro"}, {}},
 			newConsumer: newSQLConsumer(
@@ -219,12 +219,12 @@
 				),
 				consume,
 				createInvalidation("bcnlat_hydro"),
-				func() interface{} { return new(bcnlatHydroProperties) },
+				newPointSlice(func() interface{} { return new(bcnlatHydroProperties) }),
 			),
 		})
 
 	RegisterJobCreator(BCNLATIENCJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks bcnlat (IENC)",
 			depends:     [2][]string{{"fairway_marks_bcnlat_ienc"}, {}},
 			newConsumer: newSQLConsumer(
@@ -235,12 +235,12 @@
 				),
 				consume,
 				createInvalidation("bcnlat_ienc"),
-				func() interface{} { return new(bcnlatIencProperties) },
+				newPointSlice(func() interface{} { return new(bcnlatIencProperties) }),
 			),
 		})
 
 	RegisterJobCreator(BOYLATHYDROJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks boylat (HYDRO)",
 			depends:     [2][]string{{"fairway_marks_boylat_hydro"}, {}},
 			newConsumer: newSQLConsumer(
@@ -251,12 +251,12 @@
 				),
 				consume,
 				createInvalidation("boylat_hydro"),
-				func() interface{} { return new(boylatHydroProperties) },
+				newPointSlice(func() interface{} { return new(boylatHydroProperties) }),
 			),
 		})
 
 	RegisterJobCreator(BOYLATIENCJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks boylat (IENC)",
 			depends:     [2][]string{{"fairway_marks_boylat_ienc"}, {}},
 			newConsumer: newSQLConsumer(
@@ -267,12 +267,12 @@
 				),
 				consume,
 				createInvalidation("boylat_ienc"),
-				func() interface{} { return new(boylatIencProperties) },
+				newPointSlice(func() interface{} { return new(boylatIencProperties) }),
 			),
 		})
 
 	RegisterJobCreator(BOYCARJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks boycar",
 			depends:     [2][]string{{"fairway_marks_boycar"}, {}},
 			newConsumer: newSQLConsumer(
@@ -283,12 +283,12 @@
 				),
 				consume,
 				createInvalidation("boycar"),
-				func() interface{} { return new(boycarProperties) },
+				newPointSlice(func() interface{} { return new(boycarProperties) }),
 			),
 		})
 
 	RegisterJobCreator(BOYSAWJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks boysaw",
 			depends:     [2][]string{{"fairway_marks_boysaw"}, {}},
 			newConsumer: newSQLConsumer(
@@ -298,12 +298,12 @@
 				),
 				consume,
 				createInvalidation("boysaw"),
-				func() interface{} { return new(boysawProperties) },
+				newPointSlice(func() interface{} { return new(boysawProperties) }),
 			),
 		})
 
 	RegisterJobCreator(BOYSPPJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks boyspp",
 			depends:     [2][]string{{"fairway_marks_boyspp"}, {}},
 			newConsumer: newSQLConsumer(
@@ -314,12 +314,12 @@
 				),
 				consume,
 				createInvalidation("boyspp"),
-				func() interface{} { return new(boysppProperties) },
+				newPointSlice(func() interface{} { return new(boysppProperties) }),
 			),
 		})
 
 	RegisterJobCreator(DAYMARHYDROJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks daymar (HYDRO)",
 			depends:     [2][]string{{"fairway_marks_daymar_hydro"}, {}},
 			newConsumer: newSQLConsumer(
@@ -329,12 +329,12 @@
 				),
 				consume,
 				createInvalidation("daymar_hydro"),
-				func() interface{} { return new(daymarHydroProperties) },
+				newPointSlice(func() interface{} { return new(daymarHydroProperties) }),
 			),
 		})
 
 	RegisterJobCreator(DAYMARIENCJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks daymar (IENC)",
 			depends:     [2][]string{{"fairway_marks_daymar_ienc"}, {}},
 			newConsumer: newSQLConsumer(
@@ -345,12 +345,12 @@
 				),
 				consume,
 				createInvalidation("daymar_ienc"),
-				func() interface{} { return new(daymarIencProperties) },
+				newPointSlice(func() interface{} { return new(daymarIencProperties) }),
 			),
 		})
 
 	RegisterJobCreator(LIGHTSJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks lights",
 			depends:     [2][]string{{"fairway_marks_lights"}, {}},
 			newConsumer: newSQLConsumer(
@@ -364,12 +364,12 @@
 				),
 				consume,
 				createInvalidation("lights"),
-				func() interface{} { return new(lightsProperties) },
+				newPointSlice(func() interface{} { return new(lightsProperties) }),
 			),
 		})
 
 	RegisterJobCreator(NOTMRKJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks notmrk",
 			depends:     [2][]string{{"fairway_marks_lights"}, {}},
 			newConsumer: newSQLConsumer(
@@ -383,12 +383,12 @@
 				),
 				consume,
 				createInvalidation("notmrk"),
-				func() interface{} { return new(notmrkProperties) },
+				newPointSlice(func() interface{} { return new(notmrkProperties) }),
 			),
 		})
 
 	RegisterJobCreator(RTPBCNJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks rtpbcn",
 			depends:     [2][]string{{"fairway_marks_rtpbcn"}, {}},
 			newConsumer: newSQLConsumer(
@@ -398,12 +398,12 @@
 				),
 				consume,
 				createInvalidation("rtpbcn"),
-				func() interface{} { return new(rtpbcnProperties) },
+				newPointSlice(func() interface{} { return new(rtpbcnProperties) }),
 			),
 		})
 
 	RegisterJobCreator(TOPMARJobKind,
-		&PointWFSJobCreator{
+		&GeometryWFSJobCreator{
 			description: "fairway marks topmar",
 			depends:     [2][]string{{"fairway_marks_topmar"}, {}},
 			newConsumer: newSQLConsumer(
@@ -413,7 +413,7 @@
 				),
 				consume,
 				createInvalidation("topmar"),
-				func() interface{} { return new(topmarProperties) },
+				newPointSlice(func() interface{} { return new(topmarProperties) }),
 			),
 		})
 }
@@ -509,11 +509,11 @@
 `
 )
 
-func createInvalidation(fmType string) func(*SQLPointConsumer) error {
+func createInvalidation(fmType string) func(*SQLGeometryConsumer) error {
 
 	invalidateFairwayMarksSQL := fmt.Sprintf(invalidateFairwayMarksSQLtmpl, fmType)
 
-	return func(spc *SQLPointConsumer) error {
+	return func(spc *SQLGeometryConsumer) error {
 		res, err := spc.tx.ExecContext(spc.ctx, invalidateFairwayMarksSQL)
 		if err != nil {
 			return err
@@ -545,7 +545,7 @@
 	)
 }
 
-func storeAttribs(spc *SQLPointConsumer, id int64, attrs *string) {
+func storeAttribs(spc *SQLGeometryConsumer, id int64, attrs *string) {
 	if attrs == nil || *attrs == "" {
 		return
 	}
@@ -566,9 +566,8 @@
 }
 
 func consume(
-	spc *SQLPointConsumer,
-	points pointSlice,
-	properties interface{},
+	spc *SQLGeometryConsumer,
+	points, properties interface{},
 	epsg int,
 ) error {
 	var fmid int64
@@ -577,7 +576,7 @@
 			spc.ctx,
 			append(
 				[]interface{}{
-					points.asWKB(),
+					points.(*pointSlice).asWKB(),
 					epsg,
 				},
 				structs.Values(properties)...)...,