// Start the figure.
        public void BeginFigure(double x, double y, double?z, double?m)
        {
            _currentLineForSegment1 = new LRSLine(_srid);
            _currentLineForSegment2 = new LRSLine(_srid);

            // just add it to the second segment once split point is reached
            if (m != null && (_splitPointReached && m.Value.NotEqualsTo(_splitPointMeasure)))
            {
                _currentLineForSegment2.AddPoint(x, y, z, m);
                return;
            }

            if (m < _splitPointMeasure)
            {
                _currentLineForSegment1.AddPoint(x, y, null, m);
            }
            else if (m > _splitPointMeasure || IsEqualToSplitMeasure(m))
            {
                _currentLineForSegment2.AddPoint(x, y, null, m);
                _splitPointReached = IsEqualToSplitMeasure(m);
            }

            if (m != null)
            {
                _lastM = (double)m;
            }
        }
        public void LRSLineStringTest()
        {
            var lrsLine = new LRSLine(4326);
            var wkt     = lrsLine.ToString();

            Assert.AreEqual(wkt, "LINESTRING EMPTY");
            lrsLine.AddPoint(new LRSPoint(1, 1, 0, 1, 4326));
            lrsLine.AddPoint(new LRSPoint(2, 2, null, null, 4326));
            lrsLine.LocatePoint(3);
            lrsLine.AddPoint(new LRSPoint(3, 3, 0, 3, 4326), new LRSPoint(4, 4, 0, 4, 4326));

            var enumerator = lrsLine.GetEnumerator();

            enumerator.MoveNext();
            enumerator.MoveNext();
            enumerator.MoveNext();
            enumerator.MoveNext();
            var currentPoint = enumerator.Current;

            Assert.AreEqual(currentPoint, new LRSPoint(4, 4, 0, 4, 4326));
            try
            {
                enumerator.MoveNext();
                // ReSharper disable once RedundantAssignment
                currentPoint = enumerator.Current;
            }
            catch (InvalidOperationException)
            {
                enumerator.Reset();
            }
        }
        // This operates on LineStrings, multi linestring
        public void BeginFigure(double x, double y, double?z, double?m)
        {
            _currentLine = new LRSLine(_srid);
            _currentLine.AddPoint(x, y, null, _currentPointM);

            // Memorize the starting point.
            _lastPoint = SqlGeometry.Point(x, y, _srid);
        }
        // This is where the real work is done.
        public void AddLine(double x, double y, double?z, double?m)
        {
            _thisPoint      = SqlGeometry.Point(x, y, _srid);
            _currentLength += _lastPoint.STDistance(_thisPoint).Value;
            _currentLine.AddPoint(x, y, null, GetCurrentMeasure());

            // reset the last point with the current point.
            _lastPoint = _thisPoint;
        }
        // This is where the real work is done.
        public void AddLine(double x, double y, double?z, double?m)
        {
            // just add it to the second segment once split point is reached
            if (m != null && (_splitPointReached && m.Value.NotEqualsTo(_splitPointMeasure)))
            {
                _currentLineForSegment2.AddPoint(x, y, z, m);
                return;
            }

            // If current measure is less than split measure; then add it to the first segment.
            if (m < _splitPointMeasure)
            {
                _currentLineForSegment1.AddPoint(x, y, z, m);
            }

            // split measure in between last point measure and current point measure.
            else if (_splitPointMeasure > _lastM && _splitPointMeasure < m)
            {
                _currentLineForSegment1.AddPoint(_splitPoint);
                _currentLineForSegment2.AddPoint(_splitPoint);
                _currentLineForSegment2.AddPoint(x, y, z, m);
                _splitPointReached = true;
            }

            // if current measure is equal to split measure; then it is a shape point
            else if (m != null && (IsEqualToSplitMeasure(m) && _lastM.NotEqualsTo(m.Value)))
            {
                _currentLineForSegment1.AddPoint(x, y, z, m);
                _currentLineForSegment2.AddPoint(x, y, z, m);
                _splitPointReached = true;
            }

            // If current measure is greater than split measure; then add it to the second segment.
            else if (m > _splitPointMeasure)
            {
                _currentLineForSegment2.AddPoint(x, y, z, m);
            }

            // reassign current measure to last measure
            if (m != null)
            {
                _lastM = (double)m;
            }
        }
 // Just add the points to the current line segment.
 public void AddLine(double x, double y, double?z, double?m)
 {
     _currentLine.AddPoint(x, y, z, m);
 }
 // Just add the points to the current line segment.
 public void BeginFigure(double x, double y, double?z, double?m)
 {
     _currentLine = new LRSLine(_srid);
     _currentLine.AddPoint(x, y, z, m);
 }
        // 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--;
            }
        }
        // Just add the points to the current line.
        public void BeginFigure(double x, double y, double?z, double?m)
        {
            var currentM = _doUpdateM ? m + _offsetM : m;

            _currentLine.AddPoint(x, y, z, currentM);
        }
        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);
        }
Exemplo n.º 11
0
 // Start the figure.
 public void BeginFigure(double x, double y, double?z, double?m)
 {
     CurrentLine.AddPoint(new LRSPoint(x, y, z, m));
 }