comparison pkg/imports/fm.go @ 4895:9f799077a3e6 fairway-marks-import

Prevent importing non-distinct fairway marks
author Tom Gottfried <tom@intevation.de>
date Tue, 14 Jan 2020 18:24:51 +0100
parents 8eb36d0d5bdf
children 53d929f658f3
comparison
equal deleted inserted replaced
4894:8eb36d0d5bdf 4895:9f799077a3e6
133 $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21 133 $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21
134 FROM ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS newfm (newfm) 134 FROM ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS newfm (newfm)
135 WHERE pg_has_role('sys_admin', 'MEMBER') 135 WHERE pg_has_role('sys_admin', 'MEMBER')
136 OR ST_Intersects((select a from a), 136 OR ST_Intersects((select a from a),
137 ST_Transform(newfm, (select ST_SRID(a) from a))) 137 ST_Transform(newfm, (select ST_SRID(a) from a)))
138 ON CONFLICT (
139 CAST((0, geom,
140 datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom,
141 scamin, picrep, txtdsc, sordat, sorind, colour, colpat, condtn,
142 bcnshp, catlam, dirimp) AS waterway.fairway_marks)
143 )
144 DO NOTHING
138 RETURNING id 145 RETURNING id
139 ` 146 `
140 ) 147 )
141 148
142 // Do executes the actual fairway marks import. 149 // Do executes the actual fairway marks import.
195 202
196 var ( 203 var (
197 unsupported = stringCounter{} 204 unsupported = stringCounter{}
198 missingProperties int 205 missingProperties int
199 badProperties int 206 badProperties int
200 outside int 207 outsideOrDup int
201 features int 208 features int
202 ) 209 )
203 210
204 if err := dl.Download(fm.User, fm.Password, func(url string, r io.Reader) error { 211 if err := dl.Download(fm.User, fm.Password, func(url string, r io.Reader) error {
205 feedback.Info("Get features from: '%s'", url) 212 feedback.Info("Get features from: '%s'", url)
285 ).Scan(&fmid) 292 ).Scan(&fmid)
286 return err 293 return err
287 }) 294 })
288 switch { 295 switch {
289 case err == sql.ErrNoRows: 296 case err == sql.ErrNoRows:
290 outside++ 297 outsideOrDup++
291 // ignore -> filtered by responsibility_areas 298 // ignore -> filtered by responsibility_areas
292 case err != nil: 299 case err != nil:
293 feedback.Error(pgxutils.ReadableError{Err: err}.Error()) 300 feedback.Error(pgxutils.ReadableError{Err: err}.Error())
294 default: 301 default:
295 features++ 302 features++
313 320
314 if len(unsupported) != 0 { 321 if len(unsupported) != 0 {
315 feedback.Warn("Unsupported types found: %s", unsupported) 322 feedback.Warn("Unsupported types found: %s", unsupported)
316 } 323 }
317 324
318 if outside > 0 { 325 if outsideOrDup > 0 {
319 feedback.Info("Features outside responsibility area: %d", outside) 326 feedback.Info(
327 "Features outside responsibility area and duplicates: %d",
328 outsideOrDup)
320 } 329 }
321 330
322 if features == 0 { 331 if features == 0 {
323 err := errors.New("no features found") 332 err := errors.New("no valid new features found")
324 feedback.Error("%v", err)
325 return nil, err 333 return nil, err
326 } 334 }
327 335
328 if err = tx.Commit(); err == nil { 336 if err = tx.Commit(); err == nil {
329 feedback.Info("Storing %d features took %s", 337 feedback.Info("Storing %d features took %s",