Index: Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsWriter.cs =================================================================== diff -u --- Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsWriter.cs (revision 0) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Exporters/HydraulicBoundaryLocationCalculationsWriter.cs (revision 69e925ddf2b2feb9e52502ca3dc957b518f0d33d) @@ -0,0 +1,89 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.IO.Exceptions; +using Core.Components.Gis.Data; +using Core.Components.Gis.IO.Writers; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Util; + +namespace Riskeer.Integration.IO.Exporters +{ + /// + /// Shapefile writer that writes a collection of + /// as point features. + /// + internal static class HydraulicBoundaryLocationCalculationsWriter + { + /// + /// Writes the collection of as point features in a shapefile. + /// + /// The hydraulic boundary locations calculations to be written to file. + /// The path to the shapefile. + /// The header to use for the meta data. + /// Thrown when or + /// is null. + /// Thrown when is invalid. + /// Thrown when the shapefile cannot be written. + public static void WriteHydraulicBoundaryLocationCalculations(IEnumerable calculations, + string filePath, string metaDataHeader) + { + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + if (metaDataHeader == null) + { + throw new ArgumentNullException(nameof(metaDataHeader)); + } + + var pointShapeFileWriter = new PointShapeFileWriter(); + + foreach (MapPointData mapDataLocation in calculations.Select(c => CreateCalculationData(c, metaDataHeader))) + { + pointShapeFileWriter.CopyToFeature(mapDataLocation); + } + + pointShapeFileWriter.SaveAs(filePath); + } + + private static MapPointData CreateCalculationData(HydraulicBoundaryLocationCalculation calculation, string metaDataHeader) + { + return new MapPointData(calculation.HydraulicBoundaryLocation.Name) + { + Features = new[] + { + HydraulicBoundaryLocationMapDataFeaturesFactory.CreateHydraulicBoundaryLocationCalculationFeature( + calculation, metaDataHeader) + } + }; + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsWriterTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsWriterTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Exporters/HydraulicBoundaryLocationCalculationsWriterTest.cs (revision 69e925ddf2b2feb9e52502ca3dc957b518f0d33d) @@ -0,0 +1,113 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.IO; +using System.Linq; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Common.Data.Hydraulics; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.IO.TestUtil; +using Riskeer.Integration.IO.Exporters; + +namespace Riskeer.Integration.IO.Test.Exporters +{ + [TestFixture] + public class HydraulicBoundaryLocationCalculationsWriterTest + { + [Test] + public void WriteHydraulicBoundaryLocationCalculations_CalculationsNull_ThrowsArgumentNullException() + { + // Call + void Call() => HydraulicBoundaryLocationCalculationsWriter.WriteHydraulicBoundaryLocationCalculations( + null, string.Empty, string.Empty); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("calculations", exception.ParamName); + } + + [Test] + public void WriteHydraulicBoundaryLocationCalculations_FilePathNull_ThrowsArgumentNullException() + { + // Call + void Call() => HydraulicBoundaryLocationCalculationsWriter.WriteHydraulicBoundaryLocationCalculations( + Enumerable.Empty(), null, string.Empty); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + public void WriteHydraulicBoundaryLocationCalculations_MetaDataHeaderNull_ThrowsArgumentNullException() + { + // Call + void Call() => HydraulicBoundaryLocationCalculationsWriter.WriteHydraulicBoundaryLocationCalculations( + Enumerable.Empty(), string.Empty, null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("metaDataHeader", exception.ParamName); + } + + [Test] + [SetCulture("nl-NL")] + public void WriteHydraulicBoundaryLocationCalculations_ValidData_WritesShapeFile() + { + // Setup + const string fileName = "test"; + const string metaDataHeader = "header"; + string directoryPath = TestHelper.GetScratchPadPath(nameof(WriteHydraulicBoundaryLocationCalculations_ValidData_WritesShapeFile)); + string filePath = Path.Combine(directoryPath, $"{fileName}.shp"); + + // Precondition + FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, false); + + var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation("location 1")) + { + Output = new TestHydraulicBoundaryLocationCalculationOutput(0.1) + }; + + try + { + // Call + HydraulicBoundaryLocationCalculationsWriter.WriteHydraulicBoundaryLocationCalculations(new[] + { + calculation + }, filePath, metaDataHeader); + + // Assert + FileTestHelper.AssertEssentialShapefilesExist(directoryPath, fileName, true); + FileTestHelper.AssertEssentialShapefileMd5Hashes( + directoryPath, fileName, + Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO), + nameof(HydraulicBoundaryLocationCalculationsWriter)), + "ExpectedExport", 28, 8, 628); + } + finally + { + Directory.Delete(directoryPath, true); + } + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsWriter/ExpectedExport.dbf =================================================================== diff -u Binary files differ Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsWriter/ExpectedExport.shp =================================================================== diff -u Binary files differ Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/test-data/HydraulicBoundaryLocationCalculationsWriter/ExpectedExport.shx =================================================================== diff -u Binary files differ