Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Exporters/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter.cs (revision 9134b288215ec6dd8b2d1eb5f5f0c9603baa734d) @@ -0,0 +1,82 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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 Ringtoets.GrassCoverErosionOutwards.Util; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Exporters +{ + /// + /// Shapefile writer that writes the locations of a collection of + /// as point features. + /// + internal static class GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter + { + /// + /// Writes the collection of as point features in a shapefile. + /// + /// The hydraulic boundary locations to be written to file. + /// The path to the shapefile. + /// Thrown when or + /// is null. + /// Thrown when is invalid. + /// Thrown when the shapefile cannot be written. + public static void WriteHydraulicBoundaryLocations(IEnumerable locations, + string filePath) + { + if (locations == null) + { + throw new ArgumentNullException(nameof(locations)); + } + + if (filePath == null) + { + throw new ArgumentNullException(nameof(filePath)); + } + + var pointShapeFileWriter = new PointShapeFileWriter(); + + foreach (MapPointData mapDataLocation in locations.Select(CreateLocationData)) + { + pointShapeFileWriter.CopyToFeature(mapDataLocation); + } + + pointShapeFileWriter.SaveAs(filePath); + } + + private static MapPointData CreateLocationData(GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocation location) + { + return new MapPointData(location.Name) + { + Features = new[] + { + GrassCoverErosionOutwardsHydraulicBoundaryLocationMapDataFeaturesFactory.CreateHydraulicBoundaryLocationFeature( + location, new GrassCoverErosionOutwardsHydraulicBoundaryLocationExportMetaDataAttributeNameProvider()) + } + }; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Properties/AssemblyInfo.cs =================================================================== diff -u -r0819cf01b494097b764677be8dd47853e38fc223 -r9134b288215ec6dd8b2d1eb5f5f0c9603baa734d --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 0819cf01b494097b764677be8dd47853e38fc223) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 9134b288215ec6dd8b2d1eb5f5f0c9603baa734d) @@ -20,6 +20,8 @@ // All rights reserved. using System.Reflection; +using System.Runtime.CompilerServices; [assembly: AssemblyTitle("Ringtoets.GrassCoverErosionOutwards.IO")] -[assembly: AssemblyProduct("Ringtoets.GrassCoverErosionOutwards.IO")] \ No newline at end of file +[assembly: AssemblyProduct("Ringtoets.GrassCoverErosionOutwards.IO")] +[assembly: InternalsVisibleTo("Ringtoets.GrassCoverErosionOutwards.IO.Test")] \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Ringtoets.GrassCoverErosionOutwards.IO.csproj =================================================================== diff -u -re613a7c9d1e9d2cc071aa9dbad42fbffeb4d2228 -r9134b288215ec6dd8b2d1eb5f5f0c9603baa734d --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Ringtoets.GrassCoverErosionOutwards.IO.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.csproj) (revision e613a7c9d1e9d2cc071aa9dbad42fbffeb4d2228) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.IO/Ringtoets.GrassCoverErosionOutwards.IO.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.csproj) (revision 9134b288215ec6dd8b2d1eb5f5f0c9603baa734d) @@ -14,6 +14,7 @@ + @@ -41,7 +42,18 @@ {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Util + False + + {FD264FAD-E6F9-47CC-97CD-770199A8E629} + Core.Components.Gis.IO + False + + + {318BA582-88C9-4816-A54A-A7E431461DE3} + Core.Components.Gis + False + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data @@ -77,6 +89,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/GrassCoverErosionOutwardsHydraulicBoundaryLocationMapDataFeaturesFactory.cs =================================================================== diff -u -r6453240983659fd2a612062d886e13e48b093ce3 -r9134b288215ec6dd8b2d1eb5f5f0c9603baa734d --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/GrassCoverErosionOutwardsHydraulicBoundaryLocationMapDataFeaturesFactory.cs (.../GrassCoverErosionOutwardsHydraulicBoundaryLocationMapDataFeaturesFactory.cs) (revision 6453240983659fd2a612062d886e13e48b093ce3) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/GrassCoverErosionOutwardsHydraulicBoundaryLocationMapDataFeaturesFactory.cs (.../GrassCoverErosionOutwardsHydraulicBoundaryLocationMapDataFeaturesFactory.cs) (revision 9134b288215ec6dd8b2d1eb5f5f0c9603baa734d) @@ -55,16 +55,16 @@ MapFeature feature = RingtoetsMapDataFeaturesFactoryHelper.CreateSinglePointMapFeature(location.Location); feature.MetaData[RingtoetsCommonUtilResources.MetaData_ID] = location.Id; feature.MetaData[RingtoetsCommonUtilResources.MetaData_Name] = location.Name; - feature.MetaData[nameProvider.WaterLevelCalculationForMechanismSpecificFactorizedSignalingNormAttributeName] = location.WaterLevelCalculationForMechanismSpecificFactorizedSignalingNorm; - feature.MetaData[nameProvider.WaterLevelCalculationForMechanismSpecificSignalingNormAttributeName] = location.WaterLevelCalculationForMechanismSpecificSignalingNorm; - feature.MetaData[nameProvider.WaterLevelCalculationForMechanismSpecificLowerLimitNormAttributeName] = location.WaterLevelCalculationForMechanismSpecificLowerLimitNorm; - feature.MetaData[nameProvider.WaterLevelCalculationForLowerLimitNormAttributeName] = location.WaterLevelCalculationForLowerLimitNorm; - feature.MetaData[nameProvider.WaterLevelCalculationForFactorizedLowerLimitNormAttributeName] = location.WaterLevelCalculationForFactorizedLowerLimitNorm; - feature.MetaData[nameProvider.WaveHeightCalculationForMechanismSpecificFactorizedSignalingNormAttributeName] = location.WaveHeightCalculationForMechanismSpecificFactorizedSignalingNorm; - feature.MetaData[nameProvider.WaveHeightCalculationForMechanismSpecificSignalingNormAttributeName] = location.WaveHeightCalculationForMechanismSpecificSignalingNorm; - feature.MetaData[nameProvider.WaveHeightCalculationForMechanismSpecificLowerLimitNormAttributeName] = location.WaveHeightCalculationForMechanismSpecificLowerLimitNorm; - feature.MetaData[nameProvider.WaveHeightCalculationForLowerLimitNormAttributeName] = location.WaveHeightCalculationForLowerLimitNorm; - feature.MetaData[nameProvider.WaveHeightCalculationForFactorizedLowerLimitNormAttributeName] = location.WaveHeightCalculationForFactorizedLowerLimitNorm; + feature.MetaData[nameProvider.WaterLevelCalculationForMechanismSpecificFactorizedSignalingNormAttributeName] = location.WaterLevelCalculationForMechanismSpecificFactorizedSignalingNorm.Value; + feature.MetaData[nameProvider.WaterLevelCalculationForMechanismSpecificSignalingNormAttributeName] = location.WaterLevelCalculationForMechanismSpecificSignalingNorm.Value; + feature.MetaData[nameProvider.WaterLevelCalculationForMechanismSpecificLowerLimitNormAttributeName] = location.WaterLevelCalculationForMechanismSpecificLowerLimitNorm.Value; + feature.MetaData[nameProvider.WaterLevelCalculationForLowerLimitNormAttributeName] = location.WaterLevelCalculationForLowerLimitNorm.Value; + feature.MetaData[nameProvider.WaterLevelCalculationForFactorizedLowerLimitNormAttributeName] = location.WaterLevelCalculationForFactorizedLowerLimitNorm.Value; + feature.MetaData[nameProvider.WaveHeightCalculationForMechanismSpecificFactorizedSignalingNormAttributeName] = location.WaveHeightCalculationForMechanismSpecificFactorizedSignalingNorm.Value; + feature.MetaData[nameProvider.WaveHeightCalculationForMechanismSpecificSignalingNormAttributeName] = location.WaveHeightCalculationForMechanismSpecificSignalingNorm.Value; + feature.MetaData[nameProvider.WaveHeightCalculationForMechanismSpecificLowerLimitNormAttributeName] = location.WaveHeightCalculationForMechanismSpecificLowerLimitNorm.Value; + feature.MetaData[nameProvider.WaveHeightCalculationForLowerLimitNormAttributeName] = location.WaveHeightCalculationForLowerLimitNorm.Value; + feature.MetaData[nameProvider.WaveHeightCalculationForFactorizedLowerLimitNormAttributeName] = location.WaveHeightCalculationForFactorizedLowerLimitNorm.Value; return feature; } } Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriterTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriterTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Exporters/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriterTest.cs (revision 9134b288215ec6dd8b2d1eb5f5f0c9603baa734d) @@ -0,0 +1,144 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.GrassCoverErosionOutwards.IO.Exporters; +using Ringtoets.GrassCoverErosionOutwards.Util; +using Ringtoets.GrassCoverErosionOutwards.Util.TestUtil; + +namespace Ringtoets.GrassCoverErosionOutwards.IO.Test.Exporters +{ + [TestFixture] + public class GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriterTest + { + [Test] + public void WriteHydraulicBoundaryLocations_LocationsNull_ThrowsArgumentNullException() + { + // Setup + string filePath = TestHelper.GetScratchPadPath(Path.Combine("WriteHydraulicBoundaryLocations_LocationsNull_ThrowsArgumentNullException", + "test.shp")); + // Call + TestDelegate call = () => GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter.WriteHydraulicBoundaryLocations(null, filePath); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("locations", exception.ParamName); + } + + [Test] + public void WriteHydrauulicBoundaryLocations_FilePathNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter.WriteHydraulicBoundaryLocations( + new GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocation[0], null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("filePath", exception.ParamName); + } + + [Test] + public void WriteHydraulicBoundaryLocations_ValidData_WritesShapeFile() + { + // Setup + string directoryPath = TestHelper.GetScratchPadPath("WriteHydraulicBoundaryLocations_ValidData_WritesShapeFile"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.shp"); + const string baseName = "test"; + + var waterLevelCalculationForMechanismSpecificFactorizedSignalingNorm = (RoundedDouble) 0.1; + var waterLevelCalculationForMechanismSpecificSignalingNorm = (RoundedDouble) 0.2; + var waterLevelCalculationForMechanismSpecificLowerLimitNorm = (RoundedDouble) 0.3; + var waterLevelCalculationForLowerLimitNorm = (RoundedDouble) 0.4; + var waterLevelCalculationForFactorizedLowerLimitNorm = (RoundedDouble) 0.5; + var waveHeightCalculationForMechanismSpecificFactorizedSignalingNorm = (RoundedDouble) 0.6; + var waveHeightCalculationForMechanismSpecificSignalingNorm = (RoundedDouble) 0.7; + var waveHeightCalculationForMechanismSpecificLowerLimitNorm = (RoundedDouble) 0.8; + var waveHeightCalculationForLowerLimitNorm = (RoundedDouble) 0.9; + var waveHeightCalculationForFactorizedLowerLimitNorm = (RoundedDouble) 1.0; + + // Precondition + AssertEssentialShapefileExists(directoryPath, baseName, false); + + GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocation location = GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationTestHelper.Create( + waterLevelCalculationForMechanismSpecificFactorizedSignalingNorm, + waterLevelCalculationForMechanismSpecificSignalingNorm, + waterLevelCalculationForMechanismSpecificLowerLimitNorm, + waterLevelCalculationForLowerLimitNorm, + waterLevelCalculationForFactorizedLowerLimitNorm, + waveHeightCalculationForMechanismSpecificFactorizedSignalingNorm, + waveHeightCalculationForMechanismSpecificSignalingNorm, + waveHeightCalculationForMechanismSpecificLowerLimitNorm, + waveHeightCalculationForLowerLimitNorm, + waveHeightCalculationForFactorizedLowerLimitNorm); + + try + { + // Call + GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter.WriteHydraulicBoundaryLocations(new[] + { + location + }, filePath); + + // Assert + AssertEssentialShapefileExists(directoryPath, baseName, true); + AssertEssentialShapefileMd5Hashes(directoryPath, baseName); + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + private static void AssertEssentialShapefileExists(string directoryPath, string baseName, bool shouldExist) + { + string pathName = Path.Combine(directoryPath, baseName); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".shp")); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".shx")); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".dbf")); + } + + private static void AssertEssentialShapefileMd5Hashes(string directoryPath, string baseName) + { + string refPathName = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.GrassCoverErosionOutwards.IO), + nameof(GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter), "ExpectedExport"); + string pathName = Path.Combine(directoryPath, baseName); + + AssertBinaryFileContent(refPathName, pathName, ".shp", 100, 28); + AssertBinaryFileContent(refPathName, pathName, ".shx", 100, 8); + AssertBinaryFileContent(refPathName, pathName, ".dbf", 32, 841); + } + + private static void AssertBinaryFileContent(string refPathName, string pathName, string extension, int headerLength, int bodyLength) + { + byte[] refContent = File.ReadAllBytes(refPathName + extension); + byte[] content = File.ReadAllBytes(pathName + extension); + Assert.AreEqual(headerLength + bodyLength, content.Length); + Assert.AreEqual(refContent.Skip(headerLength).Take(bodyLength), + content.Skip(headerLength).Take(bodyLength)); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj =================================================================== diff -u -re613a7c9d1e9d2cc071aa9dbad42fbffeb4d2228 -r9134b288215ec6dd8b2d1eb5f5f0c9603baa734d --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj) (revision e613a7c9d1e9d2cc071aa9dbad42fbffeb4d2228) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.IO.Test.csproj) (revision 9134b288215ec6dd8b2d1eb5f5f0c9603baa734d) @@ -21,6 +21,7 @@ + @@ -79,5 +80,9 @@ {033ED27D-E806-42B4-9689-8150CFAE1906} Ringtoets.GrassCoverErosionOutwards.Util + + {C700ED66-8565-48B2-9A4E-B0D33FB2B26D} + Ringtoets.GrassCoverErosionOutwards.Util.TestUtil + \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/test-data/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter/ExpectedExport.dbf =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/test-data/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter/ExpectedExport.shp =================================================================== diff -u Binary files differ Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.IO.Test/test-data/GrassCoverErosionOutwardsHydraulicBoundaryLocationsWriter/ExpectedExport.shx =================================================================== diff -u Binary files differ