Mercurial > gemma
changeset 4907:644cb7c175f3 fairway-marks-import
Use proper type to represent featuretype
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 07 Feb 2020 19:38:48 +0100 |
parents | 21fea90f4002 |
children | 52c31d3b5131 |
files | pkg/imports/fm.go pkg/imports/fm_bcnlat.go |
diffstat | 2 files changed, 42 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/fm.go Fri Feb 07 12:35:11 2020 +0100 +++ b/pkg/imports/fm.go Fri Feb 07 19:38:48 2020 +0100 @@ -62,10 +62,11 @@ // Constructor returning pointer to struct // representing featuretype's properties newProps func() interface{}, + // Construct pointer to featuretype from given pointSlice and properties + newFeat func(pointSlice, interface{}) interface{}, ) ( - // Elements can be converted to []interface{}{p, fp} with - // p being a pointSlice and fp of the type of argument props. - fms [][]interface{}, + // Slice of features to be converted to featuretypes type + fms []interface{}, epsg int, err error, ) { @@ -147,7 +148,7 @@ return err } - f := []interface{}{p, props} + f := newFeat(p, props) fms = append(fms, f) default: unsupported[feature.Geometry.Type]++
--- a/pkg/imports/fm_bcnlat.go Fri Feb 07 12:35:11 2020 +0100 +++ b/pkg/imports/fm_bcnlat.go Fri Feb 07 19:38:48 2020 +0100 @@ -76,6 +76,11 @@ Dirimp *string `json:"ienc_dirimp,omitempty"` } +type bcnlatFeaturetype struct { + geom pointSlice + props *bcnlatProperties +} + const ( insertBCNLATSQL = ` with a as ( @@ -136,6 +141,9 @@ feedback, fm.FairwayMarks, func() interface{} { return new(bcnlatProperties) }, + func(p pointSlice, props interface{}) interface{} { + return &bcnlatFeaturetype{p, props.(*bcnlatProperties)} + }, ) if err != nil { return nil, err @@ -155,24 +163,24 @@ savepoint := Savepoint(ctx, tx, "feature") - var outsideOrDup int - - var features int + var ( + outsideOrDup int + features int + ) for _, fm := range fms { - p := fm[0].(pointSlice) - fp := fm[1].(*bcnlatProperties) + f := fm.(*bcnlatFeaturetype) var catlam sql.NullInt64 - if fp.HydroCatlam != nil { - catlam = sql.NullInt64{Int64: *fp.HydroCatlam, Valid: true} - } else if fp.IENCCatlam != nil { - catlam = sql.NullInt64{Int64: *fp.IENCCatlam, Valid: true} + if f.props.HydroCatlam != nil { + catlam = sql.NullInt64{Int64: *f.props.HydroCatlam, Valid: true} + } else if f.props.IENCCatlam != nil { + catlam = sql.NullInt64{Int64: *f.props.IENCCatlam, Valid: true} } var dirimp sql.NullInt64 - if fp.Dirimp != nil { - if value, err := strconv.ParseInt(*fp.Dirimp, 10, 64); err == nil { + if f.props.Dirimp != nil { + if value, err := strconv.ParseInt(*f.props.Dirimp, 10, 64); err == nil { dirimp = sql.NullInt64{Int64: value, Valid: true} } } @@ -181,25 +189,25 @@ err := savepoint(func() error { err := insertStmt.QueryRowContext( ctx, - p.asWKB(), + f.geom.asWKB(), epsg, - fp.Datsta, - fp.Datend, - fp.Persta, - fp.Perend, - fp.Objnam, - fp.Nobjnm, - fp.Inform, - fp.Ninfom, - fp.Scamin, - fp.Picrep, - fp.Txtdsc, - fp.Sordat, - fp.Sorind, - fp.Colour, - fp.Colpat, - fp.Condtn, - fp.Bcnshp, + f.props.Datsta, + f.props.Datend, + f.props.Persta, + f.props.Perend, + f.props.Objnam, + f.props.Nobjnm, + f.props.Inform, + f.props.Ninfom, + f.props.Scamin, + f.props.Picrep, + f.props.Txtdsc, + f.props.Sordat, + f.props.Sorind, + f.props.Colour, + f.props.Colpat, + f.props.Condtn, + f.props.Bcnshp, catlam, dirimp, ).Scan(&fmid)