// 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 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.AssessmentSection;
namespace Ringtoets.Common.IO
{
///
/// Shapefile writer that writes a as a line feature.
///
public class ReferenceLineWriter
{
///
/// Writes a as a line feature in a shapefile.
///
/// The reference line which is to be written to file.
/// The id of the assessment section to which this reference line is associated.
/// The path to the shapefile.
/// Thrown when ,
/// or is null.
/// Thrown when
/// - is invalid, or
/// - is empty or consists of whitespace.
///
/// Thrown when the shapefile cannot be written.
public void WriteReferenceLine(ReferenceLine referenceLine, string id, string filePath)
{
if (filePath == null)
{
throw new ArgumentNullException("filePath");
}
var polyLineShapeFileWriter = new PolylineShapeFileWriter();
MapLineData mapLineData = CreateMapLineData(referenceLine, id);
polyLineShapeFileWriter.CopyToFeature(mapLineData);
polyLineShapeFileWriter.SaveAs(filePath);
}
///
/// Create a new instance of from a reference line and a traject id.
///
/// The supplying the geometry information
/// for the new object.
/// The id of the assessment section to which the reference line is associated.
/// A new instance of .
/// Thrown when or
/// is null.
/// Thrown when is empty or consists of whitespace.
private static MapLineData CreateMapLineData(ReferenceLine referenceLine, string id)
{
if (referenceLine == null)
{
throw new ArgumentNullException("referenceLine");
}
if (id == null)
{
throw new ArgumentNullException("id");
}
if (string.IsNullOrWhiteSpace(id))
{
throw new ArgumentException("id");
}
MapGeometry referenceLineGeometry = new MapGeometry(
new List>
{
referenceLine.Points
});
MapFeature mapFeature = new MapFeature(new[]
{
referenceLineGeometry
});
mapFeature.MetaData.Add("TRAJECT_ID", id);
return new MapLineData("referentielijn")
{
Features = new[]
{
mapFeature
}
};
}
}
}