comparison pkg/imports/fm.go @ 4977:4bf6cde2d996

Generalize WFS point import job to be able to import other geometry types, too.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Mar 2020 18:05:33 +0100
parents e1d8217954a0
children 35a3dc12050f
comparison
equal deleted inserted replaced
4976:ff965141d085 4977:4bf6cde2d996
207 TOPMARJobKind JobKind = "fm_topmar" 207 TOPMARJobKind JobKind = "fm_topmar"
208 ) 208 )
209 209
210 func init() { 210 func init() {
211 RegisterJobCreator(BCNLATHYDROJobKind, 211 RegisterJobCreator(BCNLATHYDROJobKind,
212 &PointWFSJobCreator{ 212 &GeometryWFSJobCreator{
213 description: "fairway marks bcnlat (HYDRO)", 213 description: "fairway marks bcnlat (HYDRO)",
214 depends: [2][]string{{"fairway_marks_bcnlat_hydro"}, {}}, 214 depends: [2][]string{{"fairway_marks_bcnlat_hydro"}, {}},
215 newConsumer: newSQLConsumer( 215 newConsumer: newSQLConsumer(
216 prepareStmnts( 216 prepareStmnts(
217 createInsertFMSQL("bcnlat_hydro", 217 createInsertFMSQL("bcnlat_hydro",
218 "colour", "colpat", "condtn", "bcnshp", "catlam"), 218 "colour", "colpat", "condtn", "bcnshp", "catlam"),
219 ), 219 ),
220 consume, 220 consume,
221 createInvalidation("bcnlat_hydro"), 221 createInvalidation("bcnlat_hydro"),
222 func() interface{} { return new(bcnlatHydroProperties) }, 222 newPointSlice(func() interface{} { return new(bcnlatHydroProperties) }),
223 ), 223 ),
224 }) 224 })
225 225
226 RegisterJobCreator(BCNLATIENCJobKind, 226 RegisterJobCreator(BCNLATIENCJobKind,
227 &PointWFSJobCreator{ 227 &GeometryWFSJobCreator{
228 description: "fairway marks bcnlat (IENC)", 228 description: "fairway marks bcnlat (IENC)",
229 depends: [2][]string{{"fairway_marks_bcnlat_ienc"}, {}}, 229 depends: [2][]string{{"fairway_marks_bcnlat_ienc"}, {}},
230 newConsumer: newSQLConsumer( 230 newConsumer: newSQLConsumer(
231 prepareStmnts( 231 prepareStmnts(
232 createInsertFMSQL("bcnlat_ienc", 232 createInsertFMSQL("bcnlat_ienc",
233 "colour", "colpat", "condtn", "bcnshp", "catlam"), 233 "colour", "colpat", "condtn", "bcnshp", "catlam"),
234 insertBcnlatDirimpSQL, 234 insertBcnlatDirimpSQL,
235 ), 235 ),
236 consume, 236 consume,
237 createInvalidation("bcnlat_ienc"), 237 createInvalidation("bcnlat_ienc"),
238 func() interface{} { return new(bcnlatIencProperties) }, 238 newPointSlice(func() interface{} { return new(bcnlatIencProperties) }),
239 ), 239 ),
240 }) 240 })
241 241
242 RegisterJobCreator(BOYLATHYDROJobKind, 242 RegisterJobCreator(BOYLATHYDROJobKind,
243 &PointWFSJobCreator{ 243 &GeometryWFSJobCreator{
244 description: "fairway marks boylat (HYDRO)", 244 description: "fairway marks boylat (HYDRO)",
245 depends: [2][]string{{"fairway_marks_boylat_hydro"}, {}}, 245 depends: [2][]string{{"fairway_marks_boylat_hydro"}, {}},
246 newConsumer: newSQLConsumer( 246 newConsumer: newSQLConsumer(
247 prepareStmnts( 247 prepareStmnts(
248 createInsertFMSQL("boylat_hydro", 248 createInsertFMSQL("boylat_hydro",
249 "colour", "colpat", "conrad", 249 "colour", "colpat", "conrad",
250 "marsys", "boyshp", "catlam"), 250 "marsys", "boyshp", "catlam"),
251 ), 251 ),
252 consume, 252 consume,
253 createInvalidation("boylat_hydro"), 253 createInvalidation("boylat_hydro"),
254 func() interface{} { return new(boylatHydroProperties) }, 254 newPointSlice(func() interface{} { return new(boylatHydroProperties) }),
255 ), 255 ),
256 }) 256 })
257 257
258 RegisterJobCreator(BOYLATIENCJobKind, 258 RegisterJobCreator(BOYLATIENCJobKind,
259 &PointWFSJobCreator{ 259 &GeometryWFSJobCreator{
260 description: "fairway marks boylat (IENC)", 260 description: "fairway marks boylat (IENC)",
261 depends: [2][]string{{"fairway_marks_boylat_ienc"}, {}}, 261 depends: [2][]string{{"fairway_marks_boylat_ienc"}, {}},
262 newConsumer: newSQLConsumer( 262 newConsumer: newSQLConsumer(
263 prepareStmnts( 263 prepareStmnts(
264 createInsertFMSQL("boylat_ienc", 264 createInsertFMSQL("boylat_ienc",
265 "colour", "colpat", "conrad", 265 "colour", "colpat", "conrad",
266 "marsys", "boyshp", "catlam"), 266 "marsys", "boyshp", "catlam"),
267 ), 267 ),
268 consume, 268 consume,
269 createInvalidation("boylat_ienc"), 269 createInvalidation("boylat_ienc"),
270 func() interface{} { return new(boylatIencProperties) }, 270 newPointSlice(func() interface{} { return new(boylatIencProperties) }),
271 ), 271 ),
272 }) 272 })
273 273
274 RegisterJobCreator(BOYCARJobKind, 274 RegisterJobCreator(BOYCARJobKind,
275 &PointWFSJobCreator{ 275 &GeometryWFSJobCreator{
276 description: "fairway marks boycar", 276 description: "fairway marks boycar",
277 depends: [2][]string{{"fairway_marks_boycar"}, {}}, 277 depends: [2][]string{{"fairway_marks_boycar"}, {}},
278 newConsumer: newSQLConsumer( 278 newConsumer: newSQLConsumer(
279 prepareStmnts( 279 prepareStmnts(
280 createInsertFMSQL("boycar", 280 createInsertFMSQL("boycar",
281 "colour", "colpat", "conrad", 281 "colour", "colpat", "conrad",
282 "marsys", "boyshp", "catcam"), 282 "marsys", "boyshp", "catcam"),
283 ), 283 ),
284 consume, 284 consume,
285 createInvalidation("boycar"), 285 createInvalidation("boycar"),
286 func() interface{} { return new(boycarProperties) }, 286 newPointSlice(func() interface{} { return new(boycarProperties) }),
287 ), 287 ),
288 }) 288 })
289 289
290 RegisterJobCreator(BOYSAWJobKind, 290 RegisterJobCreator(BOYSAWJobKind,
291 &PointWFSJobCreator{ 291 &GeometryWFSJobCreator{
292 description: "fairway marks boysaw", 292 description: "fairway marks boysaw",
293 depends: [2][]string{{"fairway_marks_boysaw"}, {}}, 293 depends: [2][]string{{"fairway_marks_boysaw"}, {}},
294 newConsumer: newSQLConsumer( 294 newConsumer: newSQLConsumer(
295 prepareStmnts( 295 prepareStmnts(
296 createInsertFMSQL("boysaw", 296 createInsertFMSQL("boysaw",
297 "colour", "colpat", "conrad", "marsys", "boyshp"), 297 "colour", "colpat", "conrad", "marsys", "boyshp"),
298 ), 298 ),
299 consume, 299 consume,
300 createInvalidation("boysaw"), 300 createInvalidation("boysaw"),
301 func() interface{} { return new(boysawProperties) }, 301 newPointSlice(func() interface{} { return new(boysawProperties) }),
302 ), 302 ),
303 }) 303 })
304 304
305 RegisterJobCreator(BOYSPPJobKind, 305 RegisterJobCreator(BOYSPPJobKind,
306 &PointWFSJobCreator{ 306 &GeometryWFSJobCreator{
307 description: "fairway marks boyspp", 307 description: "fairway marks boyspp",
308 depends: [2][]string{{"fairway_marks_boyspp"}, {}}, 308 depends: [2][]string{{"fairway_marks_boyspp"}, {}},
309 newConsumer: newSQLConsumer( 309 newConsumer: newSQLConsumer(
310 prepareStmnts( 310 prepareStmnts(
311 createInsertFMSQL("boyspp", 311 createInsertFMSQL("boyspp",
312 "colour", "colpat", "conrad", 312 "colour", "colpat", "conrad",
313 "marsys", "boyshp", "catspm"), 313 "marsys", "boyshp", "catspm"),
314 ), 314 ),
315 consume, 315 consume,
316 createInvalidation("boyspp"), 316 createInvalidation("boyspp"),
317 func() interface{} { return new(boysppProperties) }, 317 newPointSlice(func() interface{} { return new(boysppProperties) }),
318 ), 318 ),
319 }) 319 })
320 320
321 RegisterJobCreator(DAYMARHYDROJobKind, 321 RegisterJobCreator(DAYMARHYDROJobKind,
322 &PointWFSJobCreator{ 322 &GeometryWFSJobCreator{
323 description: "fairway marks daymar (HYDRO)", 323 description: "fairway marks daymar (HYDRO)",
324 depends: [2][]string{{"fairway_marks_daymar_hydro"}, {}}, 324 depends: [2][]string{{"fairway_marks_daymar_hydro"}, {}},
325 newConsumer: newSQLConsumer( 325 newConsumer: newSQLConsumer(
326 prepareStmnts( 326 prepareStmnts(
327 createInsertFMSQL("daymar_hydro", 327 createInsertFMSQL("daymar_hydro",
328 "colour", "colpat", "condtn", "topshp"), 328 "colour", "colpat", "condtn", "topshp"),
329 ), 329 ),
330 consume, 330 consume,
331 createInvalidation("daymar_hydro"), 331 createInvalidation("daymar_hydro"),
332 func() interface{} { return new(daymarHydroProperties) }, 332 newPointSlice(func() interface{} { return new(daymarHydroProperties) }),
333 ), 333 ),
334 }) 334 })
335 335
336 RegisterJobCreator(DAYMARIENCJobKind, 336 RegisterJobCreator(DAYMARIENCJobKind,
337 &PointWFSJobCreator{ 337 &GeometryWFSJobCreator{
338 description: "fairway marks daymar (IENC)", 338 description: "fairway marks daymar (IENC)",
339 depends: [2][]string{{"fairway_marks_daymar_ienc"}, {}}, 339 depends: [2][]string{{"fairway_marks_daymar_ienc"}, {}},
340 newConsumer: newSQLConsumer( 340 newConsumer: newSQLConsumer(
341 prepareStmnts( 341 prepareStmnts(
342 createInsertFMSQL("daymar_ienc", 342 createInsertFMSQL("daymar_ienc",
343 "colour", "colpat", "condtn", "topshp", "orient"), 343 "colour", "colpat", "condtn", "topshp", "orient"),
344 insertDaymarDirimpSQL, 344 insertDaymarDirimpSQL,
345 ), 345 ),
346 consume, 346 consume,
347 createInvalidation("daymar_ienc"), 347 createInvalidation("daymar_ienc"),
348 func() interface{} { return new(daymarIencProperties) }, 348 newPointSlice(func() interface{} { return new(daymarIencProperties) }),
349 ), 349 ),
350 }) 350 })
351 351
352 RegisterJobCreator(LIGHTSJobKind, 352 RegisterJobCreator(LIGHTSJobKind,
353 &PointWFSJobCreator{ 353 &GeometryWFSJobCreator{
354 description: "fairway marks lights", 354 description: "fairway marks lights",
355 depends: [2][]string{{"fairway_marks_lights"}, {}}, 355 depends: [2][]string{{"fairway_marks_lights"}, {}},
356 newConsumer: newSQLConsumer( 356 newConsumer: newSQLConsumer(
357 prepareStmnts( 357 prepareStmnts(
358 createInsertFMSQL("lights", 358 createInsertFMSQL("lights",
362 "sectr2", "siggrp", "sigper", 362 "sectr2", "siggrp", "sigper",
363 "sigseq", "status"), 363 "sigseq", "status"),
364 ), 364 ),
365 consume, 365 consume,
366 createInvalidation("lights"), 366 createInvalidation("lights"),
367 func() interface{} { return new(lightsProperties) }, 367 newPointSlice(func() interface{} { return new(lightsProperties) }),
368 ), 368 ),
369 }) 369 })
370 370
371 RegisterJobCreator(NOTMRKJobKind, 371 RegisterJobCreator(NOTMRKJobKind,
372 &PointWFSJobCreator{ 372 &GeometryWFSJobCreator{
373 description: "fairway marks notmrk", 373 description: "fairway marks notmrk",
374 depends: [2][]string{{"fairway_marks_lights"}, {}}, 374 depends: [2][]string{{"fairway_marks_lights"}, {}},
375 newConsumer: newSQLConsumer( 375 newConsumer: newSQLConsumer(
376 prepareStmnts( 376 prepareStmnts(
377 createInsertFMSQL("notmrk", 377 createInsertFMSQL("notmrk",
381 "disbk2", "fnctnm", "bnkwtw"), 381 "disbk2", "fnctnm", "bnkwtw"),
382 insertNotmrkDirimpSQL, 382 insertNotmrkDirimpSQL,
383 ), 383 ),
384 consume, 384 consume,
385 createInvalidation("notmrk"), 385 createInvalidation("notmrk"),
386 func() interface{} { return new(notmrkProperties) }, 386 newPointSlice(func() interface{} { return new(notmrkProperties) }),
387 ), 387 ),
388 }) 388 })
389 389
390 RegisterJobCreator(RTPBCNJobKind, 390 RegisterJobCreator(RTPBCNJobKind,
391 &PointWFSJobCreator{ 391 &GeometryWFSJobCreator{
392 description: "fairway marks rtpbcn", 392 description: "fairway marks rtpbcn",
393 depends: [2][]string{{"fairway_marks_rtpbcn"}, {}}, 393 depends: [2][]string{{"fairway_marks_rtpbcn"}, {}},
394 newConsumer: newSQLConsumer( 394 newConsumer: newSQLConsumer(
395 prepareStmnts( 395 prepareStmnts(
396 createInsertFMSQL("rtpbcn", 396 createInsertFMSQL("rtpbcn",
397 "condtn", "siggrp", "catrtb", "radwal"), 397 "condtn", "siggrp", "catrtb", "radwal"),
398 ), 398 ),
399 consume, 399 consume,
400 createInvalidation("rtpbcn"), 400 createInvalidation("rtpbcn"),
401 func() interface{} { return new(rtpbcnProperties) }, 401 newPointSlice(func() interface{} { return new(rtpbcnProperties) }),
402 ), 402 ),
403 }) 403 })
404 404
405 RegisterJobCreator(TOPMARJobKind, 405 RegisterJobCreator(TOPMARJobKind,
406 &PointWFSJobCreator{ 406 &GeometryWFSJobCreator{
407 description: "fairway marks topmar", 407 description: "fairway marks topmar",
408 depends: [2][]string{{"fairway_marks_topmar"}, {}}, 408 depends: [2][]string{{"fairway_marks_topmar"}, {}},
409 newConsumer: newSQLConsumer( 409 newConsumer: newSQLConsumer(
410 prepareStmnts( 410 prepareStmnts(
411 createInsertFMSQL("topmar", 411 createInsertFMSQL("topmar",
412 "colour", "colpat", "condtn", "topshp"), 412 "colour", "colpat", "condtn", "topshp"),
413 ), 413 ),
414 consume, 414 consume,
415 createInvalidation("topmar"), 415 createInvalidation("topmar"),
416 func() interface{} { return new(topmarProperties) }, 416 newPointSlice(func() interface{} { return new(topmarProperties) }),
417 ), 417 ),
418 }) 418 })
419 } 419 }
420 420
421 const ( 421 const (
507 INSERT INTO waterway.fairway_marks_notmrk_dirimps (fm_notmrk_id, dirimp) 507 INSERT INTO waterway.fairway_marks_notmrk_dirimps (fm_notmrk_id, dirimp)
508 VALUES ($1, $2) 508 VALUES ($1, $2)
509 ` 509 `
510 ) 510 )
511 511
512 func createInvalidation(fmType string) func(*SQLPointConsumer) error { 512 func createInvalidation(fmType string) func(*SQLGeometryConsumer) error {
513 513
514 invalidateFairwayMarksSQL := fmt.Sprintf(invalidateFairwayMarksSQLtmpl, fmType) 514 invalidateFairwayMarksSQL := fmt.Sprintf(invalidateFairwayMarksSQLtmpl, fmType)
515 515
516 return func(spc *SQLPointConsumer) error { 516 return func(spc *SQLGeometryConsumer) error {
517 res, err := spc.tx.ExecContext(spc.ctx, invalidateFairwayMarksSQL) 517 res, err := spc.tx.ExecContext(spc.ctx, invalidateFairwayMarksSQL)
518 if err != nil { 518 if err != nil {
519 return err 519 return err
520 } 520 }
521 old, err := res.RowsAffected() 521 old, err := res.RowsAffected()
543 strings.Join(attributes, ","), 543 strings.Join(attributes, ","),
544 attNums, 544 attNums,
545 ) 545 )
546 } 546 }
547 547
548 func storeAttribs(spc *SQLPointConsumer, id int64, attrs *string) { 548 func storeAttribs(spc *SQLGeometryConsumer, id int64, attrs *string) {
549 if attrs == nil || *attrs == "" { 549 if attrs == nil || *attrs == "" {
550 return 550 return
551 } 551 }
552 dirimps := strings.Split(*attrs, ",") 552 dirimps := strings.Split(*attrs, ",")
553 for _, dirimp := range dirimps { 553 for _, dirimp := range dirimps {
564 } 564 }
565 } 565 }
566 } 566 }
567 567
568 func consume( 568 func consume(
569 spc *SQLPointConsumer, 569 spc *SQLGeometryConsumer,
570 points pointSlice, 570 points, properties interface{},
571 properties interface{},
572 epsg int, 571 epsg int,
573 ) error { 572 ) error {
574 var fmid int64 573 var fmid int64
575 err := spc.savepoint(func() error { 574 err := spc.savepoint(func() error {
576 return spc.stmts[0].QueryRowContext( 575 return spc.stmts[0].QueryRowContext(
577 spc.ctx, 576 spc.ctx,
578 append( 577 append(
579 []interface{}{ 578 []interface{}{
580 points.asWKB(), 579 points.(*pointSlice).asWKB(),
581 epsg, 580 epsg,
582 }, 581 },
583 structs.Values(properties)...)..., 582 structs.Values(properties)...)...,
584 ).Scan(&fmid) 583 ).Scan(&fmid)
585 }) 584 })