changeset 2937:0d79f5eec630

Fix logging in axis import
author Tom Gottfried <tom@intevation.de>
date Thu, 04 Apr 2019 16:14:29 +0200
parents 70946dc00abd
children ecb1e34157a3
files pkg/imports/wx.go
diffstat 1 files changed, 33 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/wx.go	Thu Apr 04 16:03:28 2019 +0200
+++ b/pkg/imports/wx.go	Thu Apr 04 16:14:29 2019 +0200
@@ -183,6 +183,7 @@
 		unsupported       = stringCounter{}
 		missingProperties int
 		badProperties     int
+		outside           int
 		features          int
 	)
 
@@ -241,11 +242,12 @@
 					epsg,
 					props,
 					nobjnam,
+					&outside,
+					&features,
 					checkCrossingStmt,
 					insertStmt); err != nil {
 					return err
 				}
-				features++
 			case "MultiLineString":
 				var ls []lineSlice
 				if err := json.Unmarshal(*feature.Geometry.Coordinates, &ls); err != nil {
@@ -260,11 +262,12 @@
 						epsg,
 						props,
 						nobjnam,
+						&outside,
+						&features,
 						checkCrossingStmt,
 						insertStmt); err != nil {
 						return err
 					}
-					features++
 				}
 			default:
 				unsupported[feature.Geometry.Type]++
@@ -287,6 +290,10 @@
 		feedback.Warn("Unsupported types found: %s", unsupported)
 	}
 
+	if outside > 0 {
+		feedback.Info("Features outside responsibility area: %d", outside)
+	}
+
 	if features == 0 {
 		return nil, errors.New("No features found")
 	}
@@ -307,10 +314,11 @@
 	epsg int,
 	props waterwayAxisProperties,
 	nobjnam sql.NullString,
+	outside, features *int,
 	checkCrossingStmt, insertStmt *sql.Stmt,
 ) error {
 	var id int
-	if err := savepoint(func() error {
+	err := savepoint(func() error {
 		err := insertStmt.QueryRowContext(
 			ctx,
 			l.asWKB(),
@@ -319,22 +327,29 @@
 			nobjnam,
 		).Scan(&id)
 		return err
-	}); err != nil {
+	})
+	switch {
+	case err == sql.ErrNoRows:
+		*outside++
+		// ignore -> filtered by responsibility_areas
+		return nil
+	case err != nil:
 		feedback.Warn(handleError(err).Error())
-	}
-
-	var crossing string
-	switch err := checkCrossingStmt.QueryRowContext(
-		ctx,
-		id,
-	).Scan(&crossing); {
-	case err != nil && err != sql.ErrNoRows:
-		return err
-	case err == nil:
-		feedback.Warn(
-			"Linestring %d crosses previously imported linestring near %s. "+
-				"Finding a contiguous axis may not work here",
-			id, crossing)
+	default:
+		*features++
+		var crossing string
+		switch err := checkCrossingStmt.QueryRowContext(
+			ctx,
+			id,
+		).Scan(&crossing); {
+		case err != nil && err != sql.ErrNoRows:
+			return err
+		case err == nil:
+			feedback.Warn(
+				"Linestring %d crosses previously imported linestring near %s. "+
+					"Finding a contiguous axis may not work here",
+				id, crossing)
+		}
 	}
 	return nil
 }