Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs
===================================================================
diff -u -r2715f4b30426f7295453b30cd7c1af97f060bcaa -rdd5ae117c10d97b388757d9d2a865c0860a64448
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs (.../ReferenceLinesMetaReader.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLinesMetaReader.cs (.../ReferenceLinesMetaReader.cs) (revision dd5ae117c10d97b388757d9d2a865c0860a64448)
@@ -39,62 +39,85 @@
///
/// Shape file reader that reads objects based on the line feature in the file.
///
- public class ReferenceLinesMetaReader : IDisposable
+ public static class ReferenceLinesMetaReader
{
private const string assessmentsectionIdAttributeKey = "TRAJECT_ID";
private const string signalingValueAttributeKey = "NORM_SW";
private const string lowerLimitValueAttributeKey = "NORM_OG";
- private readonly PolylineShapeFileReader polylineShapeFileReader;
///
- /// Initializes a new instance of the class and validates the file.
+ /// Reads the current features in the shape file into a collection of objects.
///
/// The file path to the shape file.
- /// When is invalid.
- /// Thrown when:
+ /// The created collection of objects.
+ /// Thrown when is invalid.
+ /// Thrown when current feature in the shape file:
///
/// - points to a file that does not exist.
- /// - The shape file does not contain the required attributes.
+ /// - The shape file does not contain the mandatory attributes.
+ /// - Has an empty attribute.
+ /// - The shape file has non-line geometries in it.
+ /// - Contains multiple poly lines.
///
- public ReferenceLinesMetaReader(string shapeFilePath)
+ public static List ReadReferenceLinesMetas(string shapeFilePath)
{
- FileUtils.ValidateFilePath(shapeFilePath);
- if (!File.Exists(shapeFilePath))
+ ValidateFilePath(shapeFilePath);
+
+ using (var reader = OpenPolyLineShapeFile(shapeFilePath))
{
- string message = new FileReaderErrorMessageBuilder(shapeFilePath)
- .Build(Resources.Error_File_does_not_exist);
- throw new CriticalFileReadException(message);
+ ValidateExistenceOfRequiredAttributes(reader);
+
+ return ReadReferenceLinesMetas(reader);
}
+ }
- polylineShapeFileReader = OpenPolyLineShapeFile(shapeFilePath);
+ private static List ReadReferenceLinesMetas(PolylineShapeFileReader reader)
+ {
+ var referenceLinesMetas = new List();
+ ReferenceLineMeta referenceLinesMeta;
+ do
+ {
+ referenceLinesMeta = ReadReferenceLinesMeta(reader);
+ if (referenceLinesMeta != null)
+ {
+ referenceLinesMetas.Add(referenceLinesMeta);
+ }
+ } while (referenceLinesMeta != null);
- ValidateExistenceOfRequiredAttributes();
+ return referenceLinesMetas;
}
- ///
- /// Reads the current feature in the shape file into a .
- ///
- /// The created .
- /// Thrown when current feature in the shape file:
- ///
- /// - Has an empty track id.
- /// - Does not contain poly lines.
- /// - Contains multiple poly lines.
- ///
- public ReferenceLineMeta ReadReferenceLinesMeta()
+ private static ReferenceLineMeta ReadReferenceLinesMeta(PolylineShapeFileReader reader)
{
- var lineData = ReadMapLineData();
+ var lineData = ReadMapLineData(reader);
return lineData == null ? null : CreateReferenceLineMeta(lineData);
}
- public void Dispose()
+ ///
+ /// Validates the .
+ ///
+ /// The file path to the shape file.
+ /// Thrown when is invalid.
+ /// Thrown when does not exist.
+ private static void ValidateFilePath(string shapeFilePath)
{
- polylineShapeFileReader.Dispose();
+ FileUtils.ValidateFilePath(shapeFilePath);
+ if (!File.Exists(shapeFilePath))
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(Resources.Error_File_does_not_exist);
+ throw new CriticalFileReadException(message);
+ }
}
- private void ValidateExistenceOfRequiredAttributes()
+ ///
+ /// Validates the file by checking if all mandatory attributes are present in the shape file.
+ ///
+ /// The opened shape file reader.
+ /// Thrown when the shape file lacks one of the mandatory attributes.
+ private static void ValidateExistenceOfRequiredAttributes(PolylineShapeFileReader polylineShapeFileReader)
{
- IList missingAttributes = GetMissingAttributes();
+ IList missingAttributes = GetMissingAttributes(polylineShapeFileReader);
if (missingAttributes.Count == 1)
{
var message = string.Format(RingtoetsCommonIOResources.ReferenceLinesMetaReader_File_lacks_required_Attribute_0_,
@@ -109,7 +132,7 @@
}
}
- private IList GetMissingAttributes()
+ private static IList GetMissingAttributes(PolylineShapeFileReader polylineShapeFileReader)
{
var list = new List(3);
if (!polylineShapeFileReader.HasAttribute(assessmentsectionIdAttributeKey))
@@ -127,16 +150,34 @@
return list;
}
+ ///
+ /// Opens a new to .
+ ///
+ /// Path to the shape file to read.
+ /// A new instance of the class.
+ /// Thrown when is invalid.
+ /// Thrown when:
+ ///
+ /// - points to a file that does not exist.
+ /// - The shape file has non-line geometries in it.
+ ///
+ ///
private static PolylineShapeFileReader OpenPolyLineShapeFile(string shapeFilePath)
{
return new PolylineShapeFileReader(shapeFilePath);
}
- private MapLineData ReadMapLineData()
+ private static MapLineData ReadMapLineData(PolylineShapeFileReader polylineShapeFileReader)
{
return (MapLineData) polylineShapeFileReader.ReadLine();
}
+ ///
+ /// Creates a new from the .
+ ///
+ /// The to create a from.
+ /// The newly created .
+ /// Thrown when the shape file contains multiple poly lines.
private static ReferenceLineMeta CreateReferenceLineMeta(MapLineData lineData)
{
var features = lineData.Features.ToArray();
@@ -165,6 +206,12 @@
return referenceLineMeta;
}
+ ///
+ /// Gets the geometry from the .
+ ///
+ /// The to get the geometry from.
+ /// A collection that represents the 's geometry.
+ /// Thrown when the shape file contains multiple poly lines.
private static IEnumerable GetSectionGeometry(MapFeature lineFeature)
{
var mapGeometries = lineFeature.MapGeometries.ToArray();