Index: src/Common/NetTopologySuite/LinearReferencing/LinearGeometryBuilder.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/NetTopologySuite/LinearReferencing/LinearGeometryBuilder.cs (.../LinearGeometryBuilder.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/NetTopologySuite/LinearReferencing/LinearGeometryBuilder.cs (.../LinearGeometryBuilder.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -11,57 +11,40 @@ /// public class LinearGeometryBuilder { - private IGeometryFactory geomFact = null; - private List lines = new List(); + private readonly IGeometryFactory geomFact = null; + private readonly List lines = new List(); private CoordinateList coordList = null; - private bool ignoreInvalidLines = false; - private bool fixInvalidLines = false; - - private ICoordinate lastPt = null; - /// /// /// /// public LinearGeometryBuilder(IGeometryFactory geomFact) { + LastCoordinate = null; + IgnoreInvalidLines = false; + FixInvalidLines = false; this.geomFact = geomFact; } /// /// Allows invalid lines to be fixed rather than causing Exceptions. /// An invalid line is one which has only one unique point. /// - public bool FixInvalidLines - { - get - { - return fixInvalidLines; - } - set - { - fixInvalidLines = value; - } - } + public bool FixInvalidLines { get; set; } /// /// Allows invalid lines to be ignored rather than causing Exceptions. /// An invalid line is one which has only one unique point. /// - public bool IgnoreInvalidLines - { - get - { - return ignoreInvalidLines; - } - set - { - ignoreInvalidLines = value; - } - } + public bool IgnoreInvalidLines { get; set; } /// + /// + /// + public ICoordinate LastCoordinate { get; private set; } + + /// /// Adds a point to the current line. /// /// The to add. @@ -78,31 +61,24 @@ public void Add(ICoordinate pt, bool allowRepeatedPoints) { if (coordList == null) + { coordList = new CoordinateList(); + } coordList.Add(pt, allowRepeatedPoints); - lastPt = pt; + LastCoordinate = pt; } /// - /// - /// - public ICoordinate LastCoordinate - { - get - { - return lastPt; - } - } - - /// /// Terminate the current . /// public void EndLine() { if (coordList == null) + { return; - - if (ignoreInvalidLines && coordList.Count < 2) + } + + if (IgnoreInvalidLines && coordList.Count < 2) { coordList = null; return; @@ -111,7 +87,9 @@ ICoordinate[] rawPts = coordList.ToCoordinateArray(); ICoordinate[] pts = rawPts; if (FixInvalidLines) + { pts = ValidCoordinateSequence(rawPts); + } coordList = null; ILineString line = null; @@ -124,27 +102,18 @@ // exception is due to too few points in line. // only propagate if not ignoring short lines if (!IgnoreInvalidLines) + { throw ex; + } } - if (line != null) + if (line != null) + { lines.Add(line); + } } /// - /// - /// - /// - /// - private ICoordinate[] ValidCoordinateSequence(ICoordinate[] pts) - { - if (pts.Length >= 2) - return pts; - ICoordinate[] validPts = new ICoordinate[] { pts[0], pts[0] }; - return validPts; - } - - /// /// Builds and returns the . /// /// @@ -155,5 +124,23 @@ return geomFact.BuildGeometry(lines); } + /// + /// + /// + /// + /// + private ICoordinate[] ValidCoordinateSequence(ICoordinate[] pts) + { + if (pts.Length >= 2) + { + return pts; + } + ICoordinate[] validPts = new ICoordinate[] + { + pts[0], + pts[0] + }; + return validPts; + } } -} +} \ No newline at end of file