Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs =================================================================== diff -u -r582bcc70571e4f8f4b0553b514d10b0cbc98cb1e -rde04928ebf4b99d762e35c4b6c50cf79d7644308 --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs (.../FailureMechanismSectionsImporter.cs) (revision 582bcc70571e4f8f4b0553b514d10b0cbc98cb1e) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/FailureMechanismSectionsImporter.cs (.../FailureMechanismSectionsImporter.cs) (revision de04928ebf4b99d762e35c4b6c50cf79d7644308) @@ -96,7 +96,16 @@ } NotifyProgress(Resources.Importer_ProgressText_Adding_imported_data_to_data_model, 3, 3); - AddImportedDataToModel(readFailureMechanismSections); + + IEnumerable orderedReadSections = OrderSections(readFailureMechanismSections, referenceLine); + if (!HasMatchingEndPoints(referenceLine.Points.Last(), orderedReadSections.Last().EndPoint)) + { + string message = string.Format(Resources.FailureMechanismSectionsImporter_Import_Imported_sections_from_file_0_contains_unchained_sections, FilePath); + Log.Error(message); + return false; + } + + AddImportedDataToModel(orderedReadSections); return true; } @@ -225,15 +234,14 @@ } } - private static IEnumerable SnapReadSectionsToReferenceLine(IEnumerable readSections, ReferenceLine referenceLine) + private static IEnumerable SnapReadSectionsToReferenceLine(IEnumerable failureMechanismSections, + ReferenceLine referenceLine) { - IEnumerable orderedReadSections = OrderSections(readSections, referenceLine); + double[] orderedSectionLengths = GetReferenceLineCutoffLengths(referenceLine, failureMechanismSections); - double[] orderedSectionLengths = GetReferenceLineCutoffLengths(referenceLine, orderedReadSections); - Point2D[][] splitResults = Math2D.SplitLineAtLengths(referenceLine.Points, orderedSectionLengths); - return CreateFailureMechanismSectionsSnappedOnReferenceLine(orderedReadSections, splitResults); + return CreateFailureMechanismSectionsSnappedOnReferenceLine(failureMechanismSections, splitResults); } private static IEnumerable OrderSections(IEnumerable unorderedSections, ReferenceLine referenceLine) @@ -280,16 +288,16 @@ { double shortestDistance = double.MaxValue; FailureMechanismSection closestSectionToReferencePoint = null; - Dictionary sectionReferenceLineDistances = sections.ToDictionary(s => Math.Min(referencePoint.GetEuclideanDistanceTo(s.StartPoint), - referencePoint.GetEuclideanDistanceTo(s.EndPoint)), - s => s); - foreach (KeyValuePair sectionReferenceLineDistance in sectionReferenceLineDistances) + Dictionary sectionReferenceLineDistances = sections.ToDictionary(s => s, + s => Math.Min(referencePoint.GetEuclideanDistanceTo(s.StartPoint), + referencePoint.GetEuclideanDistanceTo(s.EndPoint))); + foreach (KeyValuePair sectionReferenceLineDistance in sectionReferenceLineDistances) { - double distance = sectionReferenceLineDistance.Key; + double distance = sectionReferenceLineDistance.Value; if (distance < shortestDistance && distance <= snappingTolerance) { - shortestDistance = sectionReferenceLineDistance.Key; - closestSectionToReferencePoint = sectionReferenceLineDistance.Value; + shortestDistance = sectionReferenceLineDistance.Value; + closestSectionToReferencePoint = sectionReferenceLineDistance.Key; } } @@ -307,6 +315,11 @@ return section; } + private static bool HasMatchingEndPoints(Point2D referenceLineEndPoint, Point2D sectionEndPoint) + { + return referenceLineEndPoint.GetEuclideanDistanceTo(sectionEndPoint) < snappingTolerance; + } + private static double[] GetReferenceLineCutoffLengths(ReferenceLine referenceLine, IEnumerable orderedReadSections) { double[] orderedSectionLengths = orderedReadSections.Select(section => section.Length).ToArray(); Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -ra083279a13d4efdd702c50f37a5a8ae059e5d0ef -rde04928ebf4b99d762e35c4b6c50cf79d7644308 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a083279a13d4efdd702c50f37a5a8ae059e5d0ef) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision de04928ebf4b99d762e35c4b6c50cf79d7644308) @@ -794,6 +794,16 @@ } /// + /// Looks up a localized string similar to Er is een fout opgetreden bij het importeren van de vakindeling uit bestand '{0}': Het bestand bevat vakken die niet op elkaar aansluiten.. + /// + public static string FailureMechanismSectionsImporter_Import_Imported_sections_from_file_0_contains_unchained_sections { + get { + return ResourceManager.GetString("FailureMechanismSectionsImporter_Import_Imported_sections_from_file_0_contains_un" + + "chained_sections", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De opgetelde lengte van de vakken moet overeenkomen met de trajectlengte.. /// public static string FailureMechanismSectionsImporter_Import_Imported_sections_too_different_from_referenceline_length { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -ra083279a13d4efdd702c50f37a5a8ae059e5d0ef -rde04928ebf4b99d762e35c4b6c50cf79d7644308 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision a083279a13d4efdd702c50f37a5a8ae059e5d0ef) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision de04928ebf4b99d762e35c4b6c50cf79d7644308) @@ -886,4 +886,7 @@ Er is een fout opgetreden bij het inlezen van grondlaag '{0}' voor parameter '{1}': {2} + + Er is een fout opgetreden bij het importeren van de vakindeling uit bestand '{0}': Het bestand bevat vakken die niet op elkaar aansluiten. + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs =================================================================== diff -u -r582bcc70571e4f8f4b0553b514d10b0cbc98cb1e -rde04928ebf4b99d762e35c4b6c50cf79d7644308 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision 582bcc70571e4f8f4b0553b514d10b0cbc98cb1e) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/FailureMechanismSectionsImporterTest.cs (.../FailureMechanismSectionsImporterTest.cs) (revision de04928ebf4b99d762e35c4b6c50cf79d7644308) @@ -401,6 +401,33 @@ } [Test] + public void Import_InvalidArtificialFileBecauseUnchainedSections_CancelImportWithErrorMessage() + { + // Setup + string referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("ReferenceLine", "Artificial_referencelijn_testA.shp")); + string sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("FailureMechanismSections", "Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.shp")); + + ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath); + + var failureMechanism = new TestFailureMechanism(); + + var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath); + + // Call + var importSuccessful = true; + Action call = () => importSuccessful = importer.Import(); + + // Assert + string expectedMessage = $"Er is een fout opgetreden bij het importeren van de vakindeling uit bestand '{sectionsFilePath}': " + + "Het bestand bevat vakken die niet op elkaar aansluiten."; + TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1); + Assert.IsFalse(importSuccessful); + CollectionAssert.IsEmpty(failureMechanism.Sections); + } + + [Test] public void Import_InvalidArtificialFileBecauseSomePointsNotOnReferenceLine_CancelImportWithErrorMessage() { // Setup Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.dbf =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.prj =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.prj (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.prj (revision de04928ebf4b99d762e35c4b6c50cf79d7644308) @@ -0,0 +1 @@ +GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.qpj =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.qpj (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.qpj (revision de04928ebf4b99d762e35c4b6c50cf79d7644308) @@ -0,0 +1 @@ +GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]] Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.shp =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/FailureMechanismSections/Artificial_referencelijn_testA_InvalidVakken_UnchainedSections.shx =================================================================== diff -u Binary files differ