// When we end, we'll make all of our output calls to our target. public void EndGeometry() { // if not multi line then add the current line to the collection. if (!_isMultiLine) { _lines.AddLine(_currentLine); } // if line counter is 0 then it is multiline // if 1 then it is linestring if (_lineCounter == 0 || !_isMultiLine) { _target = _lines.ToSqlGeometry(); } else { _lines.AddLine(_currentLine); // reset the line counter so that the child line strings chaining is done and return to base multiline type _lineCounter--; } }
// This is where real work is done. public void EndGeometry() { // if not multi line then add the current line to the collection. if (!_isMultiLine) { _lines.AddLine(_currentLine); } // if line counter is 0 then it is multiline // if 1 then it is linestring if (_lineCounter == 0 || !_isMultiLine) { // reverse the line before constructing the geometry _lines.ReversLines(); _lines.TranslateMeasure(_translateMeasure); _lines.ToSqlGeometry(ref _target); } else { _lines.AddLine(_currentLine); // reset the line counter so that the child line strings chaining is done and return to base multiline type _lineCounter--; } }
// Add the current line to the MULTILINESTRING collection public void EndFigure() { MultiLine.AddLine(_currentLine); }
// add segments to target public void EndGeometry() { // if not multi line then add the current line to the collection. if (!_isMultiLine) { _segment1.AddLine(_currentLineForSegment1); _segment2.AddLine(_currentLineForSegment2); } // if line counter is 0 then it is multiline // if 1 then it is linestring if (_lineCounter == 0 || !_isMultiLine) { Segment1 = _segment1.ToSqlGeometry(); // TODO:: Messy logic to be meet as per Oracle; need to be re-factored // if second is a multi line // end measure of first line > end measure of last line // then consider only first line // by locating the point if (!_segment1.IsEmpty && _segment2.IsMultiLine) { var endSegmentEndM = _segment2.GetLastLine().GetEndPointM(); var startSegmentStartM = _segment2.GetFirstLine().GetEndPointM(); if (startSegmentStartM > endSegmentEndM) { var trimmedLine = _segment2.GetFirstLine(); var newLRSLine = new LRSLine(_srid); // add points up to end segment measure foreach (var point in trimmedLine) { if (point.M < endSegmentEndM) { newLRSLine.AddPoint(point); } } // add the end point if (endSegmentEndM.EqualsTo(_splitPointMeasure)) { newLRSLine.AddPoint(_splitPoint); } else { newLRSLine.AddPoint(trimmedLine.LocatePoint(endSegmentEndM, newLRSLine.GetEndPoint())); } Segment2 = newLRSLine.ToSqlGeometry(); } // if end segment measure is equal to split measure; then return the split alone for second segment else if (endSegmentEndM.EqualsTo(_splitPointMeasure)) { Segment2 = _splitPoint; } else { Segment2 = _segment2.ToSqlGeometry(); } } else { Segment2 = _segment2.ToSqlGeometry(); } } else { if (_currentLineForSegment1.IsLine) { _segment1.AddLine(_currentLineForSegment1); } if (_currentLineForSegment2.IsLine) { _segment2.AddLine(_currentLineForSegment2); } // reset the line counter so that the child line strings chaining is done and return to base multiline type _lineCounter--; } }
public void LRSMultiLineToSqlTest() { // empty LRS Point check var point1 = new LRSPoint("LINESTRING EMPTY".GetGeom()); var hashCode = point1.GetHashCode(); Assert.IsTrue(hashCode > 0); Assert.AreEqual(point1.ToString(), "POINT (0 0 )"); // LRS Point Equality check point1 = new LRSPoint("POINT(1 1 0 1)".GetGeom()); var point2 = new LRSPoint("POINT(1 1 0 1)".GetGeom()); Assert.IsTrue(point1 == point2); // range check Assert.IsTrue(point1.IsXYWithinTolerance(point2, 0.5)); point2 = new LRSPoint("POINT(2 2 0 2)".GetGeom()); var point3 = new LRSPoint("POINT(3 3 0 3)".GetGeom()); var point4 = new LRSPoint("POINT(4 4 0 4)".GetGeom()); var lrsPoints = new List <LRSPoint> { point1, point2, point3 }; // next and previous point Assert.AreEqual(LRSPoint.GetNextPoint(ref lrsPoints, point2), point3); Assert.AreEqual(LRSPoint.GetNextPoint(ref lrsPoints, point4), null); Assert.AreEqual(LRSPoint.GetPreviousPoint(ref lrsPoints, point2), point1); Assert.AreEqual(LRSPoint.GetPreviousPoint(ref lrsPoints, point4), null); // Multiline var lrs = new LRSMultiLine(4326); SqlGeometryBuilder geomBuilder = null; lrs.ToSqlGeometry(ref geomBuilder); lrs.BuildSqlGeometry(ref geomBuilder); geomBuilder = new SqlGeometryBuilder(); lrs.ToSqlGeometry(ref geomBuilder); lrs.BuildSqlGeometry(ref geomBuilder); var lrsLine = new LRSLine(4326); lrsLine.AddPoint(new LRSPoint(1, 1, 0, 1, 4326)); lrs.AddLine(lrsLine); geomBuilder = new SqlGeometryBuilder(); lrs.ToSqlGeometry(ref geomBuilder); var lrsLine1 = new LRSLine(4326); var wkt = lrs.ToString(); Assert.AreEqual("MULTILINESTRING EMPTY", wkt); Assert.AreEqual(lrs.GetPointAtM(10), null); var pt = new LRSPoint(1, 1, 0, 1, 4326); lrsLine1.AddPoint(pt); Assert.AreEqual(lrsLine1.ToString(), "POINT (1 1 1)"); pt = new LRSPoint(2, 2, 0, 2, 4326); lrsLine1.AddPoint(pt); lrs = new LRSMultiLine(4326); lrs.AddLine(lrsLine1); wkt = lrs.ToString(); Assert.AreEqual("LINESTRING (1 1 1, 2 2 2)", wkt); var lrsLine2 = new LRSLine(4326); pt = new LRSPoint(3, 3, 0, 3, 4326); Assert.AreEqual(pt.ToString(), "POINT (3 3 3)"); lrsLine2.AddPoint(pt); pt = new LRSPoint(4, 4, 0, 4, 4326); lrsLine2.AddPoint(pt); lrs = new LRSMultiLine(4326); lrs.AddLine(lrsLine1); lrs.AddLine(lrsLine2); geomBuilder = null; lrs.BuildSqlGeometry(ref geomBuilder); Assert.AreEqual(lrs.GetPointAtM(10), null); Assert.AreEqual(lrs.GetPointAtM(2), new LRSPoint(2, 2, 0, 2, 4326)); wkt = lrs.ToString(); lrs.RemoveFirst(); Assert.AreEqual(lrs.Count, 1); lrs.RemoveLast(); Assert.AreEqual(lrs.Count, 0); lrs.RemoveFirst(); lrs.RemoveLast(); Assert.AreEqual("MULTILINESTRING ((1 1 1, 2 2 2), (3 3 3, 4 4 4))", wkt); }