changeset 5273:9a903cdebd97 multi-geoms

Merged default into multi-geoms.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 10 Jun 2020 20:41:41 +0200
parents c84784486265 (diff) aca4bf7af270 (current diff)
children 3bab0e19f08b
files
diffstat 3 files changed, 45 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/imports/fd.go	Wed Jun 10 16:33:10 2020 +0200
+++ b/pkg/imports/fd.go	Wed Jun 10 20:41:41 2020 +0200
@@ -364,16 +364,33 @@
 			} else {
 				dateInfo = (*props.HydroSorDat).Time
 			}
+
+			var polys multiPolygonSlice
+
 			switch feature.Geometry.Type {
 			case "Polygon":
 				var p polygonSlice
 				if err := json.Unmarshal(*feature.Geometry.Coordinates, &p); err != nil {
 					return err
 				}
+				polys = multiPolygonSlice{p}
+
+			case "MultiPolygon":
+				if err := json.Unmarshal(*feature.Geometry.Coordinates, &polys); err != nil {
+					return err
+				}
+			default:
+				unsupported[feature.Geometry.Type]++
+				continue features
+			}
+
+			// Store the features.
+		storePolygons:
+			for _, p := range polys {
 				var fdid int64
 				var lat, lon float64
-				err = savepoint(func() error {
-					err := insertStmt.QueryRowContext(
+				switch err := savepoint(func() error {
+					return insertStmt.QueryRowContext(
 						ctx,
 						p.asWKB(),
 						epsg,
@@ -384,26 +401,24 @@
 						dateInfo,
 						fd.SourceOrganization,
 					).Scan(&fdid, &lat, &lon)
-					return err
-				})
-				switch {
+				}); {
 				case err == sql.ErrNoRows:
 					outside++
 					// ignore -> filtered by responsibility area (stretches)
-					continue features
+					continue storePolygons
 				case err != nil:
 					feedback.Error(pgxutils.ReadableError{Err: err}.Error())
-					continue features
+					continue storePolygons
 				}
 				// Store for potential later removal.
-				if err = track(ctx, tx, importID, "waterway.fairway_dimensions", fdid); err != nil {
+				if err := track(
+					ctx, tx, importID, "waterway.fairway_dimensions", fdid,
+				); err != nil {
 					return err
 				}
 				fds = append(fds, fdSummary{ID: fdid, Lat: lat, Lon: lon})
 
 				features++
-			default:
-				unsupported[feature.Geometry.Type]++
 			}
 		}
 		return nil
--- a/pkg/imports/wkb.go	Wed Jun 10 16:33:10 2020 +0200
+++ b/pkg/imports/wkb.go	Wed Jun 10 20:41:41 2020 +0200
@@ -25,10 +25,11 @@
 )
 
 type (
-	pointSlice     []float64
-	lineSlice      [][]float64
-	multiLineSlice []lineSlice
-	polygonSlice   [][][]float64
+	pointSlice        []float64
+	lineSlice         [][]float64
+	multiLineSlice    []lineSlice
+	polygonSlice      [][][]float64
+	multiPolygonSlice []polygonSlice
 )
 
 func newPointFeature(newProperties func() interface{}) func() (string, interface{}) {
--- a/pkg/imports/wp.go	Wed Jun 10 16:33:10 2020 +0200
+++ b/pkg/imports/wp.go	Wed Jun 10 20:41:41 2020 +0200
@@ -298,6 +298,21 @@
 					return err
 				}
 				features++
+			case "MultiLineString":
+				var ml multiLineSlice
+				if err := json.Unmarshal(*feature.Geometry.Coordinates, &ml); err != nil {
+					return err
+				}
+				for i := range ml {
+					if _, err := insertStmt.ExecContext(
+						ctx,
+						ml[i].asWKB(),
+						epsg,
+					); err != nil {
+						return err
+					}
+					features++
+				}
 			default:
 				unsupported[feature.Geometry.Type]++
 			}