// 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.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.IO.Exceptions;
using Core.Components.Gis.Data;
using Core.Components.Gis.Features;
using Core.Components.Gis.Geometries;
using Core.Components.Gis.IO.Writers;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.IO.Properties;
namespace Ringtoets.Common.IO.Hydraulics
{
///
/// Shapefile writer that writes the locations of a collection of as point features.
///
public class HydraulicBoundaryLocationsWriter
{
private readonly string designWaterLevelName;
private readonly string waveHeightName;
///
/// Creates a new instance of .
///
/// The Dutch name of the content of the
/// property.
/// The Dutch name of the content of the
/// property.
/// Thrown when or
/// is null.
public HydraulicBoundaryLocationsWriter(string designWaterLevelName, string waveHeightName)
{
if (designWaterLevelName == null)
{
throw new ArgumentNullException(nameof(designWaterLevelName));
}
if (waveHeightName == null)
{
throw new ArgumentNullException(nameof(waveHeightName));
}
this.designWaterLevelName = designWaterLevelName;
this.waveHeightName = waveHeightName;
}
///
/// 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 void WriteHydraulicBoundaryLocations(IEnumerable hydraulicBoundaryLocations,
string filePath)
{
if (hydraulicBoundaryLocations == null)
{
throw new ArgumentNullException(nameof(hydraulicBoundaryLocations));
}
if (filePath == null)
{
throw new ArgumentNullException(nameof(filePath));
}
var pointShapeFileWriter = new PointShapeFileWriter();
foreach (MapPointData mapPointData in hydraulicBoundaryLocations.Select(CreateMapPointData))
{
pointShapeFileWriter.CopyToFeature(mapPointData);
}
pointShapeFileWriter.SaveAs(filePath);
}
private MapPointData CreateMapPointData(HydraulicBoundaryLocation hydraulicBoundaryLocation)
{
if (hydraulicBoundaryLocation == null)
{
throw new ArgumentNullException(nameof(hydraulicBoundaryLocation));
}
var hydraulicBoundaryLocationGeometry = new MapGeometry(
new List>
{
new[]
{
hydraulicBoundaryLocation.Location
}
});
var mapFeature = new MapFeature(new[]
{
hydraulicBoundaryLocationGeometry
});
mapFeature.MetaData.Add(Resources.HydraulicBoundaryLocation_Name, hydraulicBoundaryLocation.Name);
mapFeature.MetaData.Add(Resources.HydraulicBoundaryLocation_Id, hydraulicBoundaryLocation.Id);
mapFeature.MetaData.Add("h(A+_A)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.DesignWaterLevelCalculation1));
mapFeature.MetaData.Add("h(A_B)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.DesignWaterLevelCalculation2));
mapFeature.MetaData.Add("h(B_C)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.DesignWaterLevelCalculation3));
mapFeature.MetaData.Add("h(C_D)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.DesignWaterLevelCalculation4));
mapFeature.MetaData.Add("Hs(A+_A)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.WaveHeightCalculation1));
mapFeature.MetaData.Add("Hs(A_B)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.WaveHeightCalculation2));
mapFeature.MetaData.Add("Hs(B_C)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.WaveHeightCalculation3));
mapFeature.MetaData.Add("Hs(C_D)", GetHydraulicBoundaryLocationOutput(hydraulicBoundaryLocation.WaveHeightCalculation4));
return new MapPointData(hydraulicBoundaryLocation.Name)
{
Features = new[]
{
mapFeature
}
};
}
private static double GetHydraulicBoundaryLocationOutput(HydraulicBoundaryLocationCalculation calculation)
{
return calculation.Output?.Result ?? double.NaN;
}
}
}