Mercurial > gemma
changeset 5270:41a67619c170 multi-geoms
Added multi geometry support for some imports.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 08 Jun 2020 19:29:40 +0200 |
parents | 528fa710650b |
children | 569aaba23e20 31c50d676bb0 |
files | pkg/imports/fd.go pkg/imports/wkb.go pkg/imports/wp.go |
diffstat | 3 files changed, 62 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/fd.go Thu Jun 04 11:29:37 2020 +0200 +++ b/pkg/imports/fd.go Mon Jun 08 19:29:40 2020 +0200 @@ -17,6 +17,7 @@ "context" "database/sql" "encoding/json" + "errors" "fmt" "io" "strings" @@ -47,6 +48,8 @@ Password string `json:"password,omitempty"` } +var errContinue = errors.New("continue") + // Description gives a short info about relevant facts of this import. func (fd *FairwayDimension) Description() (string, error) { return strings.Join([]string{ @@ -364,12 +367,10 @@ } else { dateInfo = (*props.HydroSorDat).Time } - switch feature.Geometry.Type { - case "Polygon": - var p polygonSlice - if err := json.Unmarshal(*feature.Geometry.Coordinates, &p); err != nil { - return err - } + + // Store a feature in the database. + storeFeature := func(p polygonSlice) error { + var fdid int64 var lat, lon float64 err = savepoint(func() error { @@ -390,18 +391,50 @@ case err == sql.ErrNoRows: outside++ // ignore -> filtered by responsibility area (stretches) - continue features + return errContinue case err != nil: feedback.Error(pgxutils.ReadableError{Err: err}.Error()) - continue features + return errContinue } // 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++ + + return nil + } + + switch feature.Geometry.Type { + case "Polygon": + var p polygonSlice + if err := json.Unmarshal(*feature.Geometry.Coordinates, &p); err != nil { + return err + } + switch err := storeFeature(p); { + case err == errContinue: + continue features + case err != nil: + return err + } + + case "MultiPolygon": + var mp multiPolygonSlice + if err := json.Unmarshal(*feature.Geometry.Coordinates, &mp); err != nil { + return err + } + for i := range mp { + switch err := storeFeature(mp[i]); { + case err == errContinue: + continue features + case err != nil: + return err + } + } default: unsupported[feature.Geometry.Type]++ }
--- a/pkg/imports/wkb.go Thu Jun 04 11:29:37 2020 +0200 +++ b/pkg/imports/wkb.go Mon Jun 08 19:29:40 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 Thu Jun 04 11:29:37 2020 +0200 +++ b/pkg/imports/wp.go Mon Jun 08 19:29:40 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]++ }