Mercurial > gemma
comparison pkg/imports/sr.go @ 5411:9822a840d668 marking-single-beam
Some refactoring to move marking handling to the right place in SR import.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 07 Jul 2021 09:43:41 +0200 |
parents | 8b6018ed3ffd |
children | 34bc6041e61e |
comparison
equal
deleted
inserted
replaced
5410:8b6018ed3ffd | 5411:9822a840d668 |
---|---|
465 clippingPolygon mesh.Polygon | 465 clippingPolygon mesh.Polygon |
466 clippingPolygonBuffered mesh.Polygon | 466 clippingPolygonBuffered mesh.Polygon |
467 removed map[int32]struct{} | 467 removed map[int32]struct{} |
468 polygonArea float64 | 468 polygonArea float64 |
469 clippingPolygonWKB []byte | 469 clippingPolygonWKB []byte |
470 tin *mesh.Tin | |
471 ) | 470 ) |
472 | 471 |
473 if boundary == nil { | 472 if boundary == nil { |
474 feedback.Info("No boundary given. Calulate from XYZ data.") | 473 feedback.Info("No boundary given. Calulate from XYZ data.") |
475 tooLongEdge := tri.EstimateTooLong() | 474 tooLongEdge := tri.EstimateTooLong() |
532 str.Build(tin) | 531 str.Build(tin) |
533 | 532 |
534 removed = str.Clip(&clippingPolygon) | 533 removed = str.Clip(&clippingPolygon) |
535 } | 534 } |
536 | 535 |
537 switch sr.surveyType() { | 536 if sr.surveyType() == models.SurveyTypeSingleBeam { |
538 case models.SurveyTypeMarking: | |
539 // TODO: Implement me! | |
540 return nil, errors.New("Not implemented, yet!") | |
541 | |
542 case models.SurveyTypeSingleBeam: | |
543 | 537 |
544 origDensity := float64(len(xyz)) / polygonArea | 538 origDensity := float64(len(xyz)) / polygonArea |
545 | 539 |
546 feedback.Info("Boundary area: %.2fm²", polygonArea) | 540 feedback.Info("Boundary area: %.2fm²", polygonArea) |
547 feedback.Info("Original point density: %.2f points/m²", origDensity) | 541 feedback.Info("Original point density: %.2f points/m²", origDensity) |
609 feedback.Info("Clipping triangles from new mesh.") | 603 feedback.Info("Clipping triangles from new mesh.") |
610 } | 604 } |
611 | 605 |
612 multibeam: | 606 multibeam: |
613 | 607 |
614 start = time.Now() | |
615 tin = tri.Tin() | |
616 tin.EPSG = epsg | |
617 | |
618 var str mesh.STRTree | |
619 str.Build(tin) | |
620 feedback.Info("Building clipping index took %v", time.Since(start)) | |
621 | |
622 start = time.Now() | |
623 | |
624 clippingPolygonBuffered.Indexify() | |
625 removed = str.Clip(&clippingPolygonBuffered) | |
626 feedback.Info("Clipping took %v.", time.Since(start)) | |
627 feedback.Info("Number of triangles to clip %d.", len(removed)) | |
628 | |
629 start = time.Now() | |
630 final := mesh.STRTree{Entries: 16} | 608 final := mesh.STRTree{Entries: 16} |
631 final.BuildWithout(tin, removed) | 609 |
632 | 610 if sr.surveyType() != models.SurveyTypeMarking { |
633 feedback.Info("Building final mesh took %v.", time.Since(start)) | 611 |
634 feedback.Info("Store mesh.") | 612 start = time.Now() |
613 tin := tri.Tin() | |
614 tin.EPSG = epsg | |
615 | |
616 var str mesh.STRTree | |
617 str.Build(tin) | |
618 feedback.Info("Building clipping index took %v", time.Since(start)) | |
619 | |
620 start = time.Now() | |
621 | |
622 clippingPolygonBuffered.Indexify() | |
623 removed = str.Clip(&clippingPolygonBuffered) | |
624 feedback.Info("Clipping took %v.", time.Since(start)) | |
625 feedback.Info("Number of triangles to clip %d.", len(removed)) | |
626 | |
627 start = time.Now() | |
628 final.BuildWithout(tin, removed) | |
629 | |
630 feedback.Info("Building final mesh took %v.", time.Since(start)) | |
631 feedback.Info("Store mesh.") | |
632 } | |
635 | 633 |
636 start = time.Now() | 634 start = time.Now() |
637 | 635 |
638 var ( | 636 var ( |
639 id int64 | 637 id int64 |
668 "no matching bottleneck of given name or time available: %v", err) | 666 "no matching bottleneck of given name or time available: %v", err) |
669 case err != nil: | 667 case err != nil: |
670 return nil, err | 668 return nil, err |
671 } | 669 } |
672 | 670 |
673 index, err := final.Bytes() | 671 if sr.surveyType() != models.SurveyTypeMarking { |
674 if err != nil { | 672 |
675 return nil, err | 673 index, err := final.Bytes() |
676 } | 674 if err != nil { |
677 | 675 return nil, err |
678 h := sha1.New() | 676 } |
679 h.Write(index) | 677 |
680 checksum := hex.EncodeToString(h.Sum(nil)) | 678 h := sha1.New() |
681 _, err = tx.ExecContext(ctx, insertMeshSQL, id, checksum, index) | 679 h.Write(index) |
682 if err != nil { | 680 checksum := hex.EncodeToString(h.Sum(nil)) |
683 return nil, err | 681 _, err = tx.ExecContext(ctx, insertMeshSQL, id, checksum, index) |
684 } | 682 if err != nil { |
685 feedback.Info("Storing mesh index took %s.", time.Since(start)) | 683 return nil, err |
686 err = generateIsos(ctx, tx, feedback, &final, id) | 684 } |
687 if err != nil { | 685 feedback.Info("Storing mesh index took %s.", time.Since(start)) |
688 return nil, err | 686 err = generateIsos(ctx, tx, feedback, &final, id) |
687 if err != nil { | |
688 return nil, err | |
689 } | |
690 } else { // SurveyTypeMarking | |
691 return nil, errors.New("not implemented, yet") | |
689 } | 692 } |
690 | 693 |
691 // Store for potential later removal. | 694 // Store for potential later removal. |
692 if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil { | 695 if err = track(ctx, tx, importID, "waterway.sounding_results", id); err != nil { |
693 return nil, err | 696 return nil, err |