Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFeaturesFactory.cs =================================================================== diff -u -r8905298103eb01ce13dd5c1a2f267f879d4fda3e -r3c72e841dad47bf90371626be0e181f5512ba1b0 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFeaturesFactory.cs (.../RingtoetsMapDataFeaturesFactory.cs) (revision 8905298103eb01ce13dd5c1a2f267f879d4fda3e) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapDataFeaturesFactory.cs (.../RingtoetsMapDataFeaturesFactory.cs) (revision 3c72e841dad47bf90371626be0e181f5512ba1b0) @@ -46,6 +46,29 @@ public static class RingtoetsMapDataFeaturesFactory { /// + /// Create a single representing a single line. + /// + /// The world map points describing the line. + /// The created map feature. + /// Thrown when + /// is null. + public static MapFeature CreateSingleLineMapFeature(IEnumerable points) + { + if (points == null) + { + throw new ArgumentNullException("points"); + } + + return new MapFeature(new[] + { + new MapGeometry(new[] + { + points + }) + }); + } + + /// /// Create reference line features based on the provided . /// /// The to create the reference @@ -58,8 +81,7 @@ { if (referenceLine != null) { - MapFeature feature = GetAsSingleMapFeature(referenceLine.Points); - + MapFeature feature = CreateSingleLineMapFeature(referenceLine.Points); feature.MetaData[Resources.MetaData_ID] = id; feature.MetaData[Resources.MetaData_Name] = name; feature.MetaData[Resources.MetaData_Length] = new RoundedDouble(2, Math2D.Length(referenceLine.Points)); @@ -120,8 +142,8 @@ for (int i = 0; i < hydraulicBoundaryLocations.Length; i++) { HydraulicBoundaryLocation location = hydraulicBoundaryLocations[i]; - var feature = GetAsSingleMapFeature(location.Location); + var feature = CreateSinglePointMapFeature(location.Location); feature.MetaData[Resources.MetaData_ID] = location.Id; feature.MetaData[Resources.MetaData_Name] = location.Name; feature.MetaData[designWaterLevelAttributeName] = location.DesignWaterLevel; @@ -159,7 +181,7 @@ return sections != null && sections.Any() ? new[] { - GetAsSingleMapFeature(sections.Select(sl => sl.GetStart())) + CreateSingleLineMapFeature(sections.Select(sl => sl.GetStart())) } : new MapFeature[0]; } @@ -176,7 +198,7 @@ return sections != null && sections.Any() ? new[] { - GetAsSingleMapFeature(sections.Select(sl => sl.GetLast())) + CreateSingleLineMapFeature(sections.Select(sl => sl.GetLast())) } : new MapFeature[0]; } @@ -189,9 +211,22 @@ /// null or empty. public static MapFeature[] CreateDikeProfilesFeatures(IEnumerable dikeProfiles) { - return dikeProfiles != null && dikeProfiles.Any() - ? dikeProfiles.Select(dikeProfile => GetAsSingleMapFeature(GetWorldPoints(dikeProfile))).ToArray() - : new MapFeature[0]; + if (dikeProfiles != null) + { + DikeProfile[] sourceDikeProfiles = dikeProfiles.ToArray(); + var mapFeatures = new MapFeature[sourceDikeProfiles.Length]; + for (int i = 0; i < sourceDikeProfiles.Length; i++) + { + DikeProfile profile = sourceDikeProfiles[i]; + + MapFeature feature = CreateSingleLineMapFeature(GetWorldPoints(profile)); + feature.MetaData[Resources.MetaData_Name] = profile.Name; + + mapFeatures[i] = feature; + } + return mapFeatures; + } + return new MapFeature[0]; } /// @@ -202,9 +237,22 @@ /// is null or empty. public static MapFeature[] CreateForeshoreProfilesFeatures(IEnumerable foreshoreProfiles) { - return foreshoreProfiles != null && foreshoreProfiles.Any() - ? foreshoreProfiles.Select(foreshoreProfile => GetAsSingleMapFeature(GetWorldPoints(foreshoreProfile))).ToArray() - : new MapFeature[0]; + if (foreshoreProfiles != null) + { + ForeshoreProfile[] sourceForeshoreProfiles = foreshoreProfiles.ToArray(); + var mapFeatures = new MapFeature[sourceForeshoreProfiles.Length]; + for (int i = 0; i < sourceForeshoreProfiles.Length; i++) + { + ForeshoreProfile profile = sourceForeshoreProfiles[i]; + + MapFeature feature = CreateSingleLineMapFeature(GetWorldPoints(profile)); + feature.MetaData[Resources.MetaData_Name] = profile.Name; + + mapFeatures[i] = feature; + } + return mapFeatures; + } + return new MapFeature[0]; } /// @@ -215,9 +263,22 @@ /// null or empty. public static MapFeature[] CreateStructuresFeatures(IEnumerable structures) { - return structures != null && structures.Any() - ? structures.Select(structure => GetAsSingleMapFeature(structure.Location)).ToArray() - : new MapFeature[0]; + if (structures != null) + { + StructureBase[] sourceStructures = structures.ToArray(); + var mapFeatures = new MapFeature[sourceStructures.Length]; + for (int i = 0; i < sourceStructures.Length; i++) + { + StructureBase structure = sourceStructures[i]; + + MapFeature feature = CreateSinglePointMapFeature(structure.Location); + feature.MetaData[Resources.MetaData_Name] = structure.Name; + + mapFeatures[i] = feature; + } + return mapFeatures; + } + return new MapFeature[0]; } /// @@ -233,9 +294,8 @@ { if ((calculations != null && calculations.Any())) { - MapCalculationData[] calculationData = calculations.Where(CalculationHasStructureAndHydraulicBoundaryLocation) - .Select(CreatemapCalculationData) - .ToArray(); + MapCalculationData[] calculationData = Enumerable.ToArray(calculations.Where(CalculationHasStructureAndHydraulicBoundaryLocation) + .Select(CreatemapCalculationData)); return CreateCalculationFeatures(calculationData); } @@ -259,7 +319,7 @@ for (int i = 0; i < calculationData.Length; i++) { MapCalculationData calculationItem = calculationData[i]; - MapFeature feature = GetAsSingleMapFeature(new[] + MapFeature feature = CreateSingleLineMapFeature(new[] { calculationItem.CalculationLocation, calculationItem.HydraulicBoundaryLocation.Location @@ -330,23 +390,12 @@ foreshoreProfile.Orientation); } - private static MapFeature GetAsSingleMapFeature(IEnumerable points) + private static MapFeature CreateSinglePointMapFeature(Point2D point) { return new MapFeature(new[] { new MapGeometry(new[] { - points - }) - }); - } - - private static MapFeature GetAsSingleMapFeature(Point2D point) - { - return new MapFeature(new[] - { - new MapGeometry(new[] - { new[] { point Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/RingtoetsMapDataFeaturesFactoryTest.cs =================================================================== diff -u -re182f6f394aa75e739467a77e7bcacd9a8b25429 -r3c72e841dad47bf90371626be0e181f5512ba1b0 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/RingtoetsMapDataFeaturesFactoryTest.cs (.../RingtoetsMapDataFeaturesFactoryTest.cs) (revision e182f6f394aa75e739467a77e7bcacd9a8b25429) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/RingtoetsMapDataFeaturesFactoryTest.cs (.../RingtoetsMapDataFeaturesFactoryTest.cs) (revision 3c72e841dad47bf90371626be0e181f5512ba1b0) @@ -43,6 +43,38 @@ public class RingtoetsMapDataFeaturesFactoryTest { [Test] + public void CreateSingleLineMapFeature_PointsNull_ThrowArgumentNullException() + { + // Call + TestDelegate call = () => RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("points", paramName); + } + + [Test] + public void CreateSingleLineMapFeature_WithPoints_ReturnMapFeatureWithLineGeometry() + { + // Setup + var points = new[] + { + new Point2D(1.1, 2.2), + new Point2D(3.3, 4.4), + }; + + // Call + MapFeature feature = RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(points); + + // Assert + Assert.AreEqual(1, feature.MapGeometries.Count()); + Assert.AreEqual(1, feature.MapGeometries.First().PointCollections.Count()); + CollectionAssert.AreEqual(points, feature.MapGeometries.First().PointCollections.First()); + + CollectionAssert.IsEmpty(feature.MetaData); + } + + [Test] public void CreateReferenceLineFeatures_ReferenceLineNull_ReturnsEmptyFeaturesArray() { // Call @@ -373,6 +405,64 @@ } [Test] + public void CreateStructuresFeatures_NullStructures_ReturnsEmptyCollection() + { + // Call + MapFeature[] features = RingtoetsMapDataFeaturesFactory.CreateStructuresFeatures(null); + + // Assert + CollectionAssert.IsEmpty(features); + } + + [Test] + public void CreateStructuresFeatures_EmptyStructures_ReturnsEmptyCollection() + { + // Setup + var structures = Enumerable.Empty(); + + // Call + MapFeature[] features = RingtoetsMapDataFeaturesFactory.CreateStructuresFeatures(structures); + + // Assert + CollectionAssert.IsEmpty(features); + } + + + [Test] + public void CreateStructuresFeatures_WithStructures_ReturnsCollectionWithFeatures() + { + // Setup + var structure1 = new SimpleStructure(new Point2D(1.1, 2.2), "A"); + var structure2 = new SimpleStructure(new Point2D(3.3, 4.4), "B"); + + var structures = new[] + { + structure1, + structure2 + }; + + // Call + MapFeature[] features = RingtoetsMapDataFeaturesFactory.CreateStructuresFeatures(structures); + + // Assert + Assert.AreEqual(2, features.Length); + Assert.AreEqual(1, features[0].MapGeometries.Count()); + Assert.AreEqual(1, features[1].MapGeometries.Count()); + var mapDataGeometryOne = features[0].MapGeometries.ElementAt(0).PointCollections.First().ToArray(); + var mapDataGeometryTwo = features[1].MapGeometries.ElementAt(0).PointCollections.First().ToArray(); + Assert.AreEqual(1, mapDataGeometryOne.Length); + Assert.AreEqual(1, mapDataGeometryTwo.Length); + Assert.AreEqual(structure1.Location, mapDataGeometryOne[0]); + Assert.AreEqual(structure2.Location, mapDataGeometryTwo[0]); + + const int expectedNumberOfMetaDataOptions = 1; + Assert.AreEqual(expectedNumberOfMetaDataOptions, features[0].MetaData.Count); + Assert.AreEqual(expectedNumberOfMetaDataOptions, features[1].MetaData.Count); + Assert.AreEqual(structure1.Name, features[0].MetaData["Naam"]); + Assert.AreEqual(structure2.Name, features[1].MetaData["Naam"]); + } + + [Test] public void CreateStructureCalculationsFeatures_NullLocations_ReturnsEmptyCollection() { // Call @@ -560,8 +650,14 @@ }; var dikeProfiles = new[] { - new DikeProfile(new Point2D(5, 4), roughnessPointsOne, pointsOne, null, new DikeProfile.ConstructionProperties()), - new DikeProfile(new Point2D(2, 1), roughnessPointsTwo, Enumerable.Empty(), null, new DikeProfile.ConstructionProperties()) + new DikeProfile(new Point2D(5, 4), roughnessPointsOne, pointsOne, null, new DikeProfile.ConstructionProperties + { + Name = "A" + }), + new DikeProfile(new Point2D(2, 1), roughnessPointsTwo, Enumerable.Empty(), null, new DikeProfile.ConstructionProperties + { + Name = "B" + }) }; // Call @@ -586,6 +682,12 @@ new Point2D(2, -5.3), new Point2D(2, -3.2) }, mapDataDikeGeometryTwo); + + const int expectedNumberOfMetaDataOptions = 1; + Assert.AreEqual(expectedNumberOfMetaDataOptions, features[0].MetaData.Count); + Assert.AreEqual(expectedNumberOfMetaDataOptions, features[1].MetaData.Count); + Assert.AreEqual(dikeProfiles[0].Name, features[0].MetaData["Naam"]); + Assert.AreEqual(dikeProfiles[1].Name, features[1].MetaData["Naam"]); } [Test] @@ -661,6 +763,12 @@ new Point2D(2, -2.2), new Point2D(2, -6.7) }, mapDataGeometryTwo); + + const int expectedNumberOfMetaDataOptions = 1; + Assert.AreEqual(expectedNumberOfMetaDataOptions, features[0].MetaData.Count); + Assert.AreEqual(expectedNumberOfMetaDataOptions, features[1].MetaData.Count); + Assert.AreEqual(dikeProfiles[0].Name, features[0].MetaData["Naam"]); + Assert.AreEqual(dikeProfiles[1].Name, features[1].MetaData["Naam"]); } private static void AssertEqualFeatureCollections(Point2D[] points, MapFeature[] features) @@ -704,11 +812,11 @@ private class SimpleStructure : StructureBase { - public SimpleStructure(Point2D location) + public SimpleStructure(Point2D location, string name = "name") : base(new ConstructionProperties { Location = location, - Name = "name", + Name = name, Id = "id" }) {} } Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingMapDataFeaturesFactory.cs =================================================================== diff -u -r8905298103eb01ce13dd5c1a2f267f879d4fda3e -r3c72e841dad47bf90371626be0e181f5512ba1b0 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingMapDataFeaturesFactory.cs (.../PipingMapDataFeaturesFactory.cs) (revision 8905298103eb01ce13dd5c1a2f267f879d4fda3e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/Views/PipingMapDataFeaturesFactory.cs (.../PipingMapDataFeaturesFactory.cs) (revision 3c72e841dad47bf90371626be0e181f5512ba1b0) @@ -24,7 +24,6 @@ using Core.Common.Base.Geometry; using Core.Components.Gis.Data; using Core.Components.Gis.Features; -using Core.Components.Gis.Geometries; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.Views; using Ringtoets.Piping.Data; @@ -52,15 +51,9 @@ for (int i = 0; i < surfaceLines.Length; i++) { - var surfaceLine = surfaceLines[i]; - var feature = new MapFeature(new[] - { - new MapGeometry(new[] - { - surfaceLine.Points.Select(p => new Point2D(p.X, p.Y)) - }) - }); + RingtoetsPipingSurfaceLine surfaceLine = surfaceLines[i]; + MapFeature feature = RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(GetWorldPoints(surfaceLine)); feature.MetaData[RingtoetsCommonFormsResources.MetaData_Name] = surfaceLine.Name; features[i] = feature; @@ -85,15 +78,9 @@ for (int i = 0; i < stochasticSoilModels.Length; i++) { - var stochasticSoilModel = stochasticSoilModels[i]; - var feature = new MapFeature(new[] - { - new MapGeometry(new[] - { - stochasticSoilModel.Geometry.Select(p => new Point2D(p.X, p.Y)) - }) - }); + StochasticSoilModel stochasticSoilModel = stochasticSoilModels[i]; + MapFeature feature = RingtoetsMapDataFeaturesFactory.CreateSingleLineMapFeature(GetWorldPoints(stochasticSoilModel)); feature.MetaData[RingtoetsCommonFormsResources.MetaData_Name] = stochasticSoilModel.Name; features[i] = feature; @@ -132,5 +119,15 @@ return RingtoetsMapDataFeaturesFactory.CreateCalculationFeatures(calculationData); } + + private static IEnumerable GetWorldPoints(RingtoetsPipingSurfaceLine surfaceLine) + { + return surfaceLine.Points.Select(p => new Point2D(p.X, p.Y)); + } + + private static IEnumerable GetWorldPoints(StochasticSoilModel stochasticSoilModel) + { + return stochasticSoilModel.Geometry.Select(p => new Point2D(p.X, p.Y)); + } } } \ No newline at end of file