Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -rfbf9eca188c20c352a702ee20c183e5dc3c7acf1 -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision fbf9eca188c20c352a702ee20c183e5dc3c7acf1) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -1659,6 +1659,25 @@ } /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap StructuresIcon { + get { + object obj = ResourceManager.GetObject("StructuresIcon", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized string similar to Kunstwerklocaties. + /// + public static string StructuresImporter_DisplayName { + get { + return ResourceManager.GetString("StructuresImporter_DisplayName", resourceCulture); + } + } + + /// /// Looks up a localized string similar to &Valideren. /// public static string Validate { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -rfbf9eca188c20c352a702ee20c183e5dc3c7acf1 -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision fbf9eca188c20c352a702ee20c183e5dc3c7acf1) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -661,4 +661,10 @@ Kunstwerken + + Kunstwerklocaties + + + ..\Resources\Structures.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Resources/Structures.png =================================================================== diff -u Binary files differ Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -rd7e204007a0a9e73fdfec7e570a397d4c41a463b -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision d7e204007a0a9e73fdfec7e570a397d4c41a463b) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -231,6 +231,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,279 @@ +// Copyright (C) Stichting Deltares 2016. 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.Collections.ObjectModel; +using System.IO; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using Core.Common.IO.Readers; +using log4net; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.IO.Properties; +using Ringtoets.Common.IO.Structures; + +namespace Ringtoets.Common.IO.FileImporters +{ + /// + /// Abstact class for structure importers, providing an implementation of importing point shapefiles + /// containing structure locations and csv files containing structure schematizations. + /// + public abstract class StructuresImporter : FileImporterBase + { + protected readonly ILog log = LogManager.GetLogger(typeof(StructuresImporter)); + private readonly ReferenceLine referenceLine; + + /// + /// Initializes a new instance of . + /// + /// The reference line used to check if the imported structures are intersecting it. + /// The path to the file to import from. + /// The import target. + /// Thrown when , + /// or is null. + protected StructuresImporter(ReferenceLine referenceLine, string filePath, T importTarget) + : base(filePath, importTarget) + { + if (referenceLine == null) + { + throw new ArgumentNullException("referenceLine"); + } + + this.referenceLine = referenceLine; + } + + public override bool Import() + { + ReadResult importStructureLocationsResult = ReadStructureLocations(); + if (importStructureLocationsResult.CriticalErrorOccurred) + { + return false; + } + + if (Canceled) + { + HandleUserCancellingImport(); + return false; + } + + ReadResult importStructureParameterRowsDataResult = ReadStructureParameterRowsData(); + if (importStructureParameterRowsDataResult.CriticalErrorOccurred) + { + return false; + } + + if (Canceled) + { + HandleUserCancellingImport(); + return false; + } + + CreateStructures(importStructureLocationsResult, importStructureParameterRowsDataResult); + + return true; + } + + /// + /// Act upon the user cancelling the import operation. + /// + protected virtual void HandleUserCancellingImport() + { + Canceled = false; + } + + private void CreateStructures(ReadResult importStructureLocationsResult, + ReadResult importStructureParameterRowsDataResult) + { + Dictionary> groupedRows = + importStructureParameterRowsDataResult.ImportedItems + .GroupBy(row => row.LocationId) + .ToDictionary(g => g.Key, g => g.ToList()); + + CreateSpecificStructures(importStructureLocationsResult.ImportedItems, groupedRows); + } + + /// + /// Create structure objects from location and geometry data. + /// + /// The read structure locations. + /// The read structure parameters, grouped by location identifier. + protected abstract void CreateSpecificStructures(ICollection structureLocations, + Dictionary> groupedStructureParameterRows); + + private ReadResult ReadStructureParameterRowsData() + { + NotifyProgress(Resources.StructuresImporter_ReadStructureParameterRowsData_reading_structure_data, 1, 1); + + string csvFilePath = Path.ChangeExtension(FilePath, ".csv"); + + StructuresCharacteristicsCsvReader rowsReader; + try + { + rowsReader = new StructuresCharacteristicsCsvReader(csvFilePath); + } + catch (ArgumentException exception) + { + log.Error(exception.Message); + return new ReadResult(true); + } + + int totalNumberOfRows; + try + { + totalNumberOfRows = rowsReader.GetLineCount(); + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message); + return new ReadResult(true); + } + + var rows = new List(); + + for (int i = 0; i < totalNumberOfRows; i++) + { + if (Canceled) + { + return new ReadResult(false); + } + + NotifyProgress(Resources.StructuresImporter_ReadStructureParameterRowsData_reading_structuredata, i + 1, totalNumberOfRows); + + try + { + StructuresParameterRow row = rowsReader.ReadLine(); + rows.Add(row); + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message); + } + catch (LineParseException exception) + { + log.Error(exception.Message); + } + } + + return new ReadResult(false) + { + ImportedItems = rows + }; + } + + private ReadResult ReadStructureLocations() + { + NotifyProgress(Resources.StructuresImporter_ReadStructureLocations_reading_structurelocations, 1, 1); + try + { + using (var structureLocationReader = new StructureLocationReader(FilePath)) + { + return GetStructureLocationReadResult(structureLocationReader); + } + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message); + } + catch (ArgumentException exception) + { + log.Error(exception.Message); + } + return new ReadResult(true); + } + + private ReadResult GetStructureLocationReadResult(StructureLocationReader structureLocationReader) + { + var structureLocations = new Collection(); + + int totalNumberOfSteps = structureLocationReader.GetStructureCount; + for (int i = 0; i < totalNumberOfSteps; i++) + { + if (Canceled) + { + return new ReadResult(false); + } + + try + { + NotifyProgress(Resources.StructuresImporter_GetStructureLocationReadResult_reading_structurelocation, i + 1, totalNumberOfSteps); + AddNextStructureLocation(structureLocationReader, structureLocations); + } + catch (LineParseException exception) + { + var message = string.Format( + Resources.StructuresImporter_GetStructureLocationReadResult_Error_reading_Structure_LineNumber_0_Error_1_The_Structure_is_skipped, + i + 1, + exception.Message); + log.Warn(message); + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message); + return new ReadResult(true); + } + } + return new ReadResult(false) + { + ImportedItems = structureLocations + }; + } + + /// + /// Get the next from + /// and add to in case it is close enough to the . + /// + /// Reader reading objects from a shapefile. + /// Collection of objects + /// to which the new is to be added. + /// + /// The shapefile misses a value for a required attribute. + /// The shapefile has an attribute whose type is incorrect. + /// + private void AddNextStructureLocation(StructureLocationReader structureLocationReader, ICollection structureLocations) + { + StructureLocation structureLocation = structureLocationReader.GetNextStructureLocation(); + double distanceToReferenceLine = GetDistanceToReferenceLine(structureLocation.Point); + if (distanceToReferenceLine > 1.0) + { + log.ErrorFormat(Resources.StructuresImporter_AddNextStructureLocation_0_skipping_location_outside_referenceline, structureLocation.Id); + return; + } + if (structureLocations.Any(dpl => dpl.Id.Equals(structureLocation.Id))) + { + log.WarnFormat(Resources.StructuresImporter_AddNextStructureLocation_Location_with_kwkident_0_already_read, structureLocation.Id); + } + structureLocations.Add(structureLocation); + } + + private double GetDistanceToReferenceLine(Point2D point) + { + return GetLineSegments(referenceLine.Points).Min(segment => segment.GetEuclideanDistanceToPoint(point)); + } + + private static IEnumerable GetLineSegments(IEnumerable linePoints) + { + return Math2D.ConvertLinePointsToLineSegments(linePoints); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs =================================================================== diff -u -ref33df6df23a479f0002ee7ac929865c53ed6d82 -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ef33df6df23a479f0002ee7ac929865c53ed6d82) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -1,4 +1,25 @@ -//------------------------------------------------------------------------------ +// Copyright (C) Stichting Deltares 2016. 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. + +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.18444 @@ -779,6 +800,109 @@ } /// + /// Looks up a localized string similar to Een kunstwerklocatie met KWKIDENT '{0}' ligt niet op de referentielijn. Locatie wordt overgeslagen.. + /// + public static string StructuresImporter_AddNextStructureLocation_0_skipping_location_outside_referenceline { + get { + return ResourceManager.GetString("StructuresImporter_AddNextStructureLocation_0_skipping_location_outside_reference" + + "line", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Kunstwerklocatie met KWKIDENT '{0}' is opnieuw ingelezen.. + /// + public static string StructuresImporter_AddNextStructureLocation_Location_with_kwkident_0_already_read { + get { + return ResourceManager.GetString("StructuresImporter_AddNextStructureLocation_Location_with_kwkident_0_already_read" + + "", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Kan geen geldige gegevens vinden voor kunstwerklocatie met KWKIDENT '{0}'.. + /// + public static string StructuresImporter_CreateSpecificStructures_no_structursdata_for_location_0_ { + get { + return ResourceManager.GetString("StructuresImporter_CreateSpecificStructures_no_structursdata_for_location_0_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Fout bij het lezen van kunstwerk op regel {0}. {1} Dit kunstwerk wordt overgeslagen.. + /// + public static string StructuresImporter_GetStructureLocationReadResult_Error_reading_Structure_LineNumber_0_Error_1_The_Structure_is_skipped { + get { + return ResourceManager.GetString("StructuresImporter_GetStructureLocationReadResult_Error_reading_Structure_LineNum" + + "ber_0_Error_1_The_Structure_is_skipped", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Inlezen van kunstwerklocatie.. + /// + public static string StructuresImporter_GetStructureLocationReadResult_reading_structurelocation { + get { + return ResourceManager.GetString("StructuresImporter_GetStructureLocationReadResult_reading_structurelocation", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Inlezen van kunstwerklocaties uit een shapebestand.. + /// + public static string StructuresImporter_ReadStructureLocations_reading_structurelocations { + get { + return ResourceManager.GetString("StructuresImporter_ReadStructureLocations_reading_structurelocations", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Inlezen van kunstwerkgegevens uit een kommagescheiden bestand.. + /// + public static string StructuresImporter_ReadStructureParameterRowsData_reading_structure_data { + get { + return ResourceManager.GetString("StructuresImporter_ReadStructureParameterRowsData_reading_structure_data", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Inlezen van kunstwerkgegevens.. + /// + public static string StructuresImporter_ReadStructureParameterRowsData_reading_structuredata { + get { + return ResourceManager.GetString("StructuresImporter_ReadStructureParameterRowsData_reading_structuredata", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parameter '{0}' ontbreekt voor de kunstwerklocatie met KWKIDENT '{1}'.. + /// + public static string StructuresImporter_ValidateParameterNames_Parameter_0_missing_for_structure_1_ { + get { + return ResourceManager.GetString("StructuresImporter_ValidateParameterNames_Parameter_0_missing_for_structure_1_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parameter '{0}' wordt herhaald voor de kunstwerklocatie met KWKIDENT '{1}'.. + /// + public static string StructuresImporter_ValidateParameterNames_Parameter_0_repeated_for_structure_1_ { + get { + return ResourceManager.GetString("StructuresImporter_ValidateParameterNames_Parameter_0_repeated_for_structure_1_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Kunstwerklocatie met KWKIDENT '{0}' bevat teveel parameters. De verwachte parameters zijn: '{1}'.. + /// + public static string StructuresImporter_ValidateParameterNames_Structure_0_has_too_many_parameters_expected_parameters_1_ { + get { + return ResourceManager.GetString("StructuresImporter_ValidateParameterNames_Structure_0_has_too_many_parameters_exp" + + "ected_parameters_1_", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het kunstwerk heeft geen geldige waarde voor attribuut '{0}'.. /// public static string StructuresReader_GetNextStructure_Invalid_KWKIDENT { Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx =================================================================== diff -u -ref33df6df23a479f0002ee7ac929865c53ed6d82 -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision ef33df6df23a479f0002ee7ac929865c53ed6d82) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -335,4 +335,37 @@ De 'Boolean' kolom mag uitsluitend de waardes '0' of '1' bevatten, of mag leeg zijn. + + Een kunstwerklocatie met KWKIDENT '{0}' ligt niet op de referentielijn. Locatie wordt overgeslagen. + + + Kunstwerklocatie met KWKIDENT '{0}' is opnieuw ingelezen. + + + Fout bij het lezen van kunstwerk op regel {0}. {1} Dit kunstwerk wordt overgeslagen. + + + Inlezen van kunstwerklocatie. + + + Inlezen van kunstwerklocaties uit een shapebestand. + + + Inlezen van kunstwerkgegevens uit een kommagescheiden bestand. + + + Inlezen van kunstwerkgegevens. + + + Kan geen geldige gegevens vinden voor kunstwerklocatie met KWKIDENT '{0}'. + + + Kunstwerklocatie met KWKIDENT '{0}' bevat teveel parameters. De verwachte parameters zijn: '{1}'. + + + Parameter '{0}' ontbreekt voor de kunstwerklocatie met KWKIDENT '{1}'. + + + Parameter '{0}' wordt herhaald voor de kunstwerklocatie met KWKIDENT '{1}'. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r653c18f73b4404d9ac58d818845474d68e48635d -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 653c18f73b4404d9ac58d818845474d68e48635d) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -56,6 +56,7 @@ + @@ -71,9 +72,9 @@ - + - + Fisheye: Tag 423010168fe01b2373e9be55f047659911e670f5 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/Structures/Structure.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructureLocation.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructureLocation.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructureLocation.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry; + +namespace Ringtoets.Common.IO.Structures +{ + /// + /// Representation of a structure as read from a shapefile. + /// + public class StructureLocation + { + /// + /// Creates a new instance of . + /// + /// The identifier for this . + /// The name of this . + /// The coordinates of this . + /// Thrown when any parameter is null. + public StructureLocation(string id, string name, Point2D point) + { + if (id == null) + { + throw new ArgumentNullException("id"); + } + if (name == null) + { + throw new ArgumentNullException("name"); + } + if (point == null) + { + throw new ArgumentNullException("point"); + } + Id = id; + Name = name; + Point = point; + } + + /// + /// Gets the identifier for this . + /// + public string Id { get; private set; } + + /// + /// Gets the name of this . + /// + public string Name { get; private set; } + + /// + /// Gets the actual location of this . + /// + public Point2D Point { get; private set; } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructureLocationReader.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructureLocationReader.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructureLocationReader.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,169 @@ +// Copyright (C) Stichting Deltares 2016. 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.IO; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.IO.Exceptions; +using Core.Common.Utils; +using Core.Common.Utils.Builders; +using Core.Components.Gis.Data; +using Core.Components.Gis.IO.Readers; +using Ringtoets.Common.IO.Properties; +using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources; + +namespace Ringtoets.Common.IO.Structures +{ + /// + /// This class is responsible for reading structures for instances. + /// + public class StructureLocationReader : IDisposable + { + private const string idAttributeName = "KWKIDENT"; + private const string nameAttributeName = "KWKNAAM"; + private readonly PointShapeFileReader pointsShapeFileReader; + + /// + /// Initializes a new instance of the class. + /// + /// The shape file path. + /// Thrown when is invalid. + /// Thrown when: + /// points to a file that does not exist. + /// does not only contain point features. + /// does not contain all of the required attributes. + /// + public StructureLocationReader(string shapeFilePath) + { + FileUtils.ValidateFilePath(shapeFilePath); + if (!File.Exists(shapeFilePath)) + { + string message = new FileReaderErrorMessageBuilder(shapeFilePath) + .Build(CoreCommonUtilsResources.Error_File_does_not_exist); + throw new CriticalFileReadException(message); + } + + pointsShapeFileReader = OpenPointsShapeFile(shapeFilePath); + + CheckRequiredAttributePresence(); + } + + /// + /// Gets the number of structures present in the shapefile. + /// + public int GetStructureCount + { + get + { + return pointsShapeFileReader.GetNumberOfFeatures(); + } + } + + /// + /// Retrieve a based on the next point feature in the shapefile. + /// + /// Thrown when either: + /// + /// The shapefile misses a value for a required attribute. + /// The shapefile has an attribute whose type is incorrect. + /// + /// A based on the next point feature in the shapefile. + public StructureLocation GetNextStructureLocation() + { + MapPointData mapPointData = (MapPointData) pointsShapeFileReader.ReadFeature(); + + IDictionary attributes = mapPointData.Features.First().MetaData; + + string attributeIdValue = GetIdAttributeValue(attributes); + string attributeNameValue = GetNameAttributeValue(attributes, attributeIdValue); + + Point2D point = mapPointData.Features.First().MapGeometries.First().PointCollections.First().First(); + if (attributeIdValue == null) + { + throw new LineParseException(string.Format(Resources.StructuresReader_GetNextStructure_Invalid_KWKIDENT, idAttributeName)); + } + return new StructureLocation(attributeIdValue, attributeNameValue, point); + } + + public void Dispose() + { + pointsShapeFileReader.Dispose(); + } + + private static string GetIdAttributeValue(IDictionary attributes) + { + var attributeIdValue = attributes[idAttributeName] as string; + return attributeIdValue; + } + + private string GetNameAttributeValue(IDictionary attributes, string defaultName) + { + if (!pointsShapeFileReader.HasAttribute(nameAttributeName)) + { + return defaultName; + } + var attributeNameValue = attributes[nameAttributeName] as string; + return string.IsNullOrWhiteSpace(attributeNameValue) ? defaultName : attributeNameValue; + } + + /// + /// Open a shapefile containing structures as point features. + /// + /// Shape file path. + /// Thrown when is invalid. + /// Thrown when: + /// + /// points to a file that doesn't exist. + /// The shapefile has non-point geometries in it. + /// An unexpected error occurred when reading the shapefile. + /// + /// Return an instance of . + private static PointShapeFileReader OpenPointsShapeFile(string shapeFilePath) + { + try + { + return new PointShapeFileReader(shapeFilePath); + } + catch (CriticalFileReadException e) + { + if (e.InnerException is ApplicationException) + { + string message = new FileReaderErrorMessageBuilder(shapeFilePath) + .Build(Resources.PointShapefileReader_File_can_only_contain_points); + throw new CriticalFileReadException(message, e); + } + + throw; + } + } + + private void CheckRequiredAttributePresence() + { + if (!pointsShapeFileReader.HasAttribute(idAttributeName)) + { + throw new CriticalFileReadException( + string.Format(Resources.ProfileLocationReader_CheckRequiredAttributePresence_Missing_attribute_0_, idAttributeName)); + } + } + } +} \ No newline at end of file Fisheye: Tag 423010168fe01b2373e9be55f047659911e670f5 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/Structures/StructuresReader.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,31 @@ +// Copyright (C) Stichting Deltares 2016. 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 NUnit.Framework; + +namespace Ringtoets.Common.IO.Test.FileImporters +{ + [TestFixture] + public class StructuresImporterTest + { + + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r653c18f73b4404d9ac58d818845474d68e48635d -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 653c18f73b4404d9ac58d818845474d68e48635d) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -59,6 +59,7 @@ + @@ -68,10 +69,10 @@ + + - - Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureLocationReaderTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureLocationReaderTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureLocationReaderTest.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,325 @@ +// Copyright (C) Stichting Deltares 2016. 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.IO; +using Core.Common.Base.Geometry; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.IO.Structures; + +namespace Ringtoets.Common.IO.Test.Structures +{ + [TestFixture] + public class StructureLocationReaderTest + { + [Test] + public void Constructor_ValidFilePath_ExpectedValues() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); + + // Call + using (var reader = new StructureLocationReader(validFilePath)) + { + // Assert + Assert.IsInstanceOf(reader); + } + } + + [Test] + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void Constructor_FilePathIsNullOrWhiteSpace_ThrowArgumentException(string invalidFilePath) + { + // Call + TestDelegate call = () => new StructureLocationReader(invalidFilePath); + + // Assert + var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet leeg of ongedefinieerd zijn.", + invalidFilePath); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void Constructor_FilePathHasInvalidPathCharacter_ThrowArgumentException() + { + // Setup + char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); + + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); + string invalidFilePath = validFilePath.Replace("e", invalidFileNameChars[1].ToString()); + + // Call + TestDelegate call = () => new StructureLocationReader(invalidFilePath); + + // Assert + var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet de volgende tekens bevatten: {1}", + invalidFilePath, string.Join(", ", invalidFileNameChars)); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void Constructor_FilePathIsActuallyDirectoryPath_ThrowArgumentException() + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.DirectorySeparatorChar.ToString()); + + // Call + TestDelegate call = () => new StructureLocationReader(invalidFilePath); + + // Assert + var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestandspad mag niet verwijzen naar een lege bestandsnaam.", + invalidFilePath); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void Constructor_FileDoesNotExist_ThrowCriticalFileReadException() + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "I_do_not_exist.shp"); + + // Call + TestDelegate call = () => new StructureLocationReader(invalidFilePath); + + // Assert + var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand bestaat niet.", + invalidFilePath); + var message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + [TestCase("Multiple_Polygon_with_ID.shp")] + [TestCase("Multiple_PolyLine_with_ID.shp")] + [TestCase("Single_Multi-Polygon_with_ID.shp")] + [TestCase("Single_Multi-PolyLine_with_ID.shp")] + [TestCase("Single_Polygon_with_ID.shp")] + [TestCase("Single_PolyLine_with_ID.shp")] + public void Constructor_ShapefileDoesNotHavePointFeatures_ThrowCriticalFileReadException(string shapeFileName) + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, shapeFileName); + + // Call + TestDelegate call = () => new StructureLocationReader(invalidFilePath); + + // Assert + var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Kon geen punten vinden in dit bestand.", + invalidFilePath); + var message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + public void Constructor_ShapefileWithoutAttributeKWKIDENT_ThrowCriticalFileReadException() + { + // Setup + string invalidFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "StructuresWithoutKWKIDENT", "Kunstwerken.shp")); + + // Call + TestDelegate call = () => new StructureLocationReader(invalidFilePath); + + // Assert + var expectedMessage = string.Format("Het bestand heeft geen attribuut '{0}'. Dit attribuut is vereist.", + "KWKIDENT"); + string message = Assert.Throws(call).Message; + Assert.AreEqual(expectedMessage, message); + } + + [Test] + public void Constructor_FileInUse_ThrowCriticalFileReadException() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); + + using (new FileStream(validFilePath, FileMode.Open)) + { + // Call + TestDelegate call = () => new StructureLocationReader(validFilePath); + + // Assert + var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Het bestand kon niet worden geopend. Mogelijk is het bestand corrupt of in gebruik door een andere applicatie.", + validFilePath); + var exception = Assert.Throws(call); + Assert.AreEqual(expectedMessage, exception.Message); + Assert.IsInstanceOf(exception.InnerException); + } + } + + [Test] + public void GetStructureCount_FileWithSixPoints_GetSix() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); + + using (var reader = new StructureLocationReader(validFilePath)) + { + // Call + int count = reader.GetStructureCount; + + // Assert + Assert.AreEqual(6, count); + } + } + + [Test] + public void GetNextStructure_ShapefileWithoutAttributeKWKNAAM_NamesEqualAttributeKWKIDENT() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "StructuresWithoutKWKNAAM", "Kunstwerken.shp")); + IList structures = new List(); + + using (var reader = new StructureLocationReader(validFilePath)) + { + // Call + int count = reader.GetStructureCount; + for (int i = 0; i < count; i++) + { + structures.Add(reader.GetNextStructureLocation()); + } + + // Assert + Assert.AreEqual(structures[0].Id, structures[0].Name); + Assert.AreEqual(structures[1].Id, structures[1].Name); + Assert.AreEqual(structures[2].Id, structures[2].Name); + Assert.AreEqual(structures[3].Id, structures[3].Name); + Assert.AreEqual(structures[4].Id, structures[4].Name); + Assert.AreEqual(structures[5].Id, structures[5].Name); + } + } + + [Test] + public void GetNextStructure_ShapefileAttributeKWKNAAMSometimesNullOrWhitespace_GetSixStructuresWithCorrectAttributes() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "StructuresSomeWithEmptyKWKNAAM", "Kunstwerken.shp")); + IList structures = new List(); + + using (var reader = new StructureLocationReader(validFilePath)) + { + // Call + int count = reader.GetStructureCount; + for (int i = 0; i < count; i++) + { + structures.Add(reader.GetNextStructureLocation()); + } + + // Assert + Assert.AreEqual(6, structures.Count); + + Assert.AreEqual("Coupure Den Oever (90k1)", structures[0].Name); + Assert.AreEqual("KUNST2", structures[1].Name); + Assert.AreEqual("Gemaal Lely (93k4)", structures[2].Name); + Assert.AreEqual("Gemaal de Stontele (94k1)", structures[3].Name); + Assert.AreEqual("KUNST5", structures[4].Name); + Assert.AreEqual("KUNST6", structures[5].Name); + } + } + + [Test] + public void GetNextStructure_ShapefileAttributeKWKIDENTValuesAreNull_ThrowLineParseException() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "StructuresWithNullKWKIDENT", "Kunstwerken.shp")); + + using (var reader = new StructureLocationReader(validFilePath)) + { + // Call + TestDelegate call = () => reader.GetNextStructureLocation(); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("Het kunstwerk heeft geen geldige waarde voor attribuut 'KWKIDENT'.", exception.Message); + } + } + + [Test] + public void GetNextStructure_FileWithSixStructures_GetSixStructuresWithCorrectAttributes() + { + // Setup + string validFilePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); + IList structures = new List(); + + using (var reader = new StructureLocationReader(validFilePath)) + { + // Call + int count = reader.GetStructureCount; + for (int i = 0; i < count; i++) + { + structures.Add(reader.GetNextStructureLocation()); + } + + // Assert + Assert.AreEqual(6, structures.Count); + + Assert.AreEqual("KUNST1", structures[0].Id); + Assert.AreEqual("KUNST2", structures[1].Id); + Assert.AreEqual("KUNST3", structures[2].Id); + Assert.AreEqual("KUNST4", structures[3].Id); + Assert.AreEqual("KUNST5", structures[4].Id); + Assert.AreEqual("KUNST6", structures[5].Id); + + Assert.AreEqual("Coupure Den Oever (90k1)", structures[0].Name); + Assert.AreEqual("Gemaal Leemans (93k3)", structures[1].Name); + Assert.AreEqual("Gemaal Lely (93k4)", structures[2].Name); + Assert.AreEqual("Gemaal de Stontele (94k1)", structures[3].Name); + Assert.AreEqual("Stontelerkeersluis (93k1)", structures[4].Name); + Assert.AreEqual("Stontelerschutsluis (93k2)", structures[5].Name); + + Assert.IsInstanceOf(typeof(Point2D), structures[0].Point); + Assert.IsInstanceOf(typeof(Point2D), structures[1].Point); + Assert.IsInstanceOf(typeof(Point2D), structures[2].Point); + Assert.IsInstanceOf(typeof(Point2D), structures[3].Point); + Assert.IsInstanceOf(typeof(Point2D), structures[4].Point); + Assert.IsInstanceOf(typeof(Point2D), structures[5].Point); + + Assert.AreEqual(131144.094, structures[0].Point.X); + Assert.AreEqual(131538.705, structures[1].Point.X); + Assert.AreEqual(135878.442, structures[2].Point.X); + Assert.AreEqual(131225.017, structures[3].Point.X); + Assert.AreEqual(131270.38, structures[4].Point.X); + Assert.AreEqual(131507.119, structures[5].Point.X); + + Assert.AreEqual(549979.893, structures[0].Point.Y); + Assert.AreEqual(548316.752, structures[1].Point.Y); + Assert.AreEqual(532149.859, structures[2].Point.Y); + Assert.AreEqual(548395.948, structures[3].Point.Y); + Assert.AreEqual(548367.462, structures[4].Point.Y); + Assert.AreEqual(548322.951, structures[5].Point.Y); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureLocationTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureLocationTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureLocationTest.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,81 @@ +// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.IO.Structures; + +namespace Ringtoets.Common.IO.Test.Structures +{ + [TestFixture] + public class StructureLocationTest + { + private const string id = "anId"; + private const string name = "aName"; + private readonly Point2D point = new Point2D(0, 0); + + [Test] + public void Constructor_IdNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new StructureLocation(null, name, point); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("id", paramName); + } + + [Test] + public void Constructor_NameNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new StructureLocation(id, null, point); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("name", paramName); + } + + [Test] + public void Constructor_PointNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => new StructureLocation(id, name, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("point", paramName); + } + + [Test] + public void Constructor_ValidParameters_ExpectedProperties() + { + // Call + var structure = new StructureLocation(id, name, point); + + // Assert + Assert.AreEqual("anId", structure.Id); + Assert.AreEqual("aName", structure.Name); + Assert.AreEqual(new Point2D(0, 0), structure.Point); + } + } +} \ No newline at end of file Fisheye: Tag 423010168fe01b2373e9be55f047659911e670f5 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructureTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 423010168fe01b2373e9be55f047659911e670f5 refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.IO.Test/Structures/StructuresReaderTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs =================================================================== diff -u -r3500ad219742fca6d4a9057e8c92435dde8d8fc1 -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs (.../HeightStructure.cs) (revision 3500ad219742fca6d4a9057e8c92435dde8d8fc1) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs (.../HeightStructure.cs) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -19,12 +19,154 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Ringtoets.Common.Data.Probabilistics; + namespace Ringtoets.HeightStructures.Data { /// /// Definition of a height structure for the . /// public class HeightStructure { + /// + /// Creates a new instance of . + /// + /// The name of the height structure. + /// The identifier of the height structure. + /// The location of the height structure. + /// The orientation of the height structure, relative to north. + /// The mean crest level of the height structure. + /// The standard deviation of the crest level of the height structure. + /// The mean flow width of the height structure at the bottom protection. + /// The standard deviation of the flow width of the height structure at the bottom protection. + /// The mean critical overtopping discharge of the height structure. + /// The standard deviation of critical overtopping discharge of the height structure. + /// The mean flow apertures width of the height structure. + /// The standard deviation of flow apertures width of the height structure. + /// The failure probability of the height structure, given erosion. + /// The mean storage area of the height structure. + /// The standard deviation of storage area of the height structure. + /// The mean allowable increase of level for storage of the height structure. + /// The standard deviation of allowable increase of level for storage of the height structure. + /// Thrown when or is null. + /// Thrown when is null. + public HeightStructure(string name, string id, Point2D location, + double orientationOfTheNormalOfTheStructure, + double levelOfCrestOfStructureMean, double levelOfCrestOfStructureStandardDeviation, + double flowWidthAtBottomProtectionMean, double flowWidthAtBottomProtectionStandardDeviation, + double criticalOvertoppingDischargeMean, double criticalOvertoppingDischargeStandardDeviation, + double widthOfFlowAperturesMean, double widthOfFlowAperturesStandardDeviation, + double failureProbabilityOfStructureGivenErosion, + double storageStructureAreaMean, double storageStructureAreaStandardDeviation, + double allowableIncreaseOfLevelForStorageMean, double allowableIncreaseOfLevelForStorageStandardDeviation + ) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentException("name"); + } + if (string.IsNullOrWhiteSpace(id)) + { + throw new ArgumentException("id"); + } + if (location == null) + { + throw new ArgumentNullException("location"); + } + + Name = name; + Id = id; + Location = location; + OrientationOfTheNormalOfTheStructure = new RoundedDouble(2, orientationOfTheNormalOfTheStructure); + LevelOfCrestOfStructure = new NormalDistribution(2) + { + Mean = new RoundedDouble(2, levelOfCrestOfStructureMean), + StandardDeviation = new RoundedDouble(2, levelOfCrestOfStructureStandardDeviation) + }; + FlowWidthAtBottomProtection = new LogNormalDistribution(2) + { + Mean = new RoundedDouble(2, flowWidthAtBottomProtectionMean), + StandardDeviation = new RoundedDouble(2, flowWidthAtBottomProtectionStandardDeviation) + }; + CriticalOvertoppingDischarge = new LogNormalDistribution(2) + { + Mean = new RoundedDouble(2, criticalOvertoppingDischargeMean), + StandardDeviation = new RoundedDouble(2, criticalOvertoppingDischargeStandardDeviation) + }; + WidthOfFlowApertures = new NormalDistribution(2) + { + Mean = new RoundedDouble(2, widthOfFlowAperturesMean), + StandardDeviation = new RoundedDouble(2, widthOfFlowAperturesStandardDeviation) + }; + FailureProbabilityOfStructureGivenErosion = failureProbabilityOfStructureGivenErosion; + StorageStructureArea = new LogNormalDistribution(2) + { + Mean = new RoundedDouble(2, storageStructureAreaMean), + StandardDeviation = new RoundedDouble(2, storageStructureAreaStandardDeviation) + }; + AllowableIncreaseOfLevelForStorage = new LogNormalDistribution(2) + { + Mean = new RoundedDouble(2, allowableIncreaseOfLevelForStorageMean), + StandardDeviation = new RoundedDouble(2, allowableIncreaseOfLevelForStorageStandardDeviation) + }; + } + + /// + /// Gets the name of the height structure. + /// + public string Name { get; private set; } + + /// + /// Gets the identifier of the height structure. + /// + public string Id { get; private set; } + + /// + /// Gets the location of the height structure. + /// + public Point2D Location { get; private set; } + + /// + /// Gets the orientation of the height structure, relative to north. + /// + public RoundedDouble OrientationOfTheNormalOfTheStructure { get; private set; } + + /// + /// Gets the crest level of the height structure. + /// + public NormalDistribution LevelOfCrestOfStructure { get; private set; } + + /// + /// Gets the flow width of the height structure at the bottom protection. + /// + public LogNormalDistribution FlowWidthAtBottomProtection { get; private set; } + + /// + /// Gets the critical overtopping discharge of the height structure. + /// + public LogNormalDistribution CriticalOvertoppingDischarge { get; private set; } + + /// + /// Gets the flow apertures width of the height structure. + /// + public NormalDistribution WidthOfFlowApertures { get; private set; } + + /// + /// Gets the failure probability of the height structure, given erosion. + /// + public double FailureProbabilityOfStructureGivenErosion { get; private set; } + + /// + /// Gets the storage area of the height structure. + /// + public LogNormalDistribution StorageStructureArea { get; private set; } + + /// + /// Gets the allowable increase of level for storage of the height structure. + /// + public LogNormalDistribution AllowableIncreaseOfLevelForStorage { get; private set; } } -} +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs =================================================================== diff -u --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (revision 0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -0,0 +1,150 @@ +// Copyright (C) Stichting Deltares 2016. 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.Base; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.IO.Properties; +using Ringtoets.Common.IO.Structures; +using Ringtoets.HeightStructures.Data; +using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; + +namespace Ringtoets.HeightStructures.IO +{ + /// + /// Imports point shapefiles containing height structure locations and csv files containing height structure schematizations. + /// + public class HeightStructuresImporter : StructuresImporter> + { + private static readonly string[] requiredParameterNames = + { + "KW_HOOGTE1", + "KW_HOOGTE2", + "KW_HOOGTE3", + "KW_HOOGTE4", + "KW_HOOGTE5", + "KW_HOOGTE6", + "KW_HOOGTE7", + "KW_HOOGTE8" + }; + + private readonly ObservableList importTarget; + + /// + /// Creates a new instance of . + /// + /// The height structures to import on. + /// The reference line used to check if the + /// objects found in the file are intersecting it. + /// The path to the file to import from. + /// Thrown when , + /// or is null. + public HeightStructuresImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath) + : base(referenceLine, filePath, importTarget) + { + this.importTarget = importTarget; + } + + protected override void CreateSpecificStructures(ICollection structureLocations, + Dictionary> groupedStructureParameterRows) + { + IEnumerable importedHeightStructures = CreateHeightStructures(structureLocations, groupedStructureParameterRows); + + foreach (HeightStructure heightStructure in importedHeightStructures) + { + importTarget.Add(heightStructure); + } + } + + private IEnumerable CreateHeightStructures(IEnumerable structureLocations, + Dictionary> groupedStructureParameterRows) + { + var heightStructures = new List(); + foreach (StructureLocation structureLocation in structureLocations) + { + string id = structureLocation.Id; + + if (!groupedStructureParameterRows.ContainsKey(id)) + { + log.ErrorFormat(Resources.StructuresImporter_CreateSpecificStructures_no_structursdata_for_location_0_, id); + continue; + } + + List structureParameterRows = groupedStructureParameterRows[id]; + if (!ValidateParameterNames(structureParameterRows, id)) + { + continue; + } + + HeightStructure heightStructure = CreateHeightStructure(structureLocation, structureParameterRows); + heightStructures.Add(heightStructure); + } + return heightStructures; + } + + private bool ValidateParameterNames(List structureParameterRows, string id) + { + bool isValid = true; + if (structureParameterRows.Count > requiredParameterNames.Length) + { + log.ErrorFormat(RingtoetsCommonIOResources.StructuresImporter_ValidateParameterNames_Structure_0_has_too_many_parameters_expected_parameters_1_, id, string.Join(", ", requiredParameterNames)); + isValid = false; + } + + foreach (string name in requiredParameterNames) + { + int count = structureParameterRows.Count(row => row.ParameterId.Equals(name)); + if (count < 1) + { + log.ErrorFormat(RingtoetsCommonIOResources.StructuresImporter_ValidateParameterNames_Parameter_0_missing_for_structure_1_, name, id); + isValid = false; + } + if (count > 1) + { + log.ErrorFormat(RingtoetsCommonIOResources.StructuresImporter_ValidateParameterNames_Parameter_0_repeated_for_structure_1_, name, id); + isValid = false; + } + } + return isValid; + } + + private static HeightStructure CreateHeightStructure(StructureLocation structureLocation, List structureParameterRows) + { + var heightStructure = new HeightStructure( + structureLocation.Name, + structureLocation.Id, + structureLocation.Point, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE1").NumericalValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE2").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE2").VarianceValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE3").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE3").VarianceValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").VarianceValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").VarianceValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE6").NumericalValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").VarianceValue, + structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").VarianceValue + ); + return heightStructure; + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj =================================================================== diff -u -r60bd3c063c8173f762c5762096efa38b87f780ed -r423010168fe01b2373e9be55f047659911e670f5 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj (.../Ringtoets.HeightStructures.IO.csproj) (revision 60bd3c063c8173f762c5762096efa38b87f780ed) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Ringtoets.HeightStructures.IO.csproj (.../Ringtoets.HeightStructures.IO.csproj) (revision 423010168fe01b2373e9be55f047659911e670f5) @@ -32,20 +32,58 @@ AllRules.ruleset + + ..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll + True + Properties\GlobalAssembly.cs + Copying.licenseheader + + + + {3BBFD65B-B277-4E50-AE6D-BD24C3434609} + Core.Common.Base + False + + + {e344867e-9ac9-44c8-88a5-8185681679a9} + Core.Common.IO + False + + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Utils + False + + + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} + Ringtoets.Common.Data + False + + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + False + + + {1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99} + Ringtoets.HeightStructures.Data + False + +