예제 #1
0
        private bool IsSimpleLinearGeometry(Geometry geom)
        {
            if (geom.IsEmpty)
            {
                return(true);
            }

            var graph = new GeometryGraph(0, geom);
            var li    = new RobustLineIntersector();
            var si    = graph.ComputeSelfNodes(li, true);

            // if no self-intersection, must be simple
            if (!si.HasIntersection)
            {
                return(true);
            }
            if (si.HasProperIntersection)
            {
                _nonSimpleLocation = si.ProperIntersectionPoint;
                return(false);
            }
            if (HasNonEndpointIntersection(graph))
            {
                return(false);
            }
            if (_isClosedEndpointsInInterior)
            {
                if (HasClosedEndpointIntersection(graph))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public static Geometry SegmentIntersection(Geometry g1, Geometry g2)
        {
            var pt1 = g1.Coordinates;
            var pt2 = g2.Coordinates;
            var ri  = new RobustLineIntersector();

            ri.ComputeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]);
            switch (ri.IntersectionNum)
            {
            case 0:
                // no intersection => return empty point
                return(g1.Factory.CreatePoint((Coordinate)null));

            case 1:
                // return point
                return(g1.Factory.CreatePoint(ri.GetIntersection(0)));

            case 2:
                // return line
                return(g1.Factory.CreateLineString(
                           new Coordinate[] {
                    ri.GetIntersection(0),
                    ri.GetIntersection(1)
                }));
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Checks validity of a LinearRing.
        /// </summary>
        /// <param name="g"></param>
        private void CheckValid(ILinearRing g)
        {
            CheckInvalidCoordinates(g.Coordinates);
            if (validErr != null)
            {
                return;
            }
            CheckClosedRing(g);
            if (validErr != null)
            {
                return;
            }

            GeometryGraph graph = new GeometryGraph(0, g);

            CheckTooFewPoints(graph);
            if (validErr != null)
            {
                return;
            }
            LineIntersector li = new RobustLineIntersector();

            graph.ComputeSelfNodes(li, true);
            CheckNoSelfIntersectingRings(graph);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <returns></returns>
        private bool IsSimpleLinearGeometry(IGeometry geom)
        {
            if (geom.IsEmpty)
            {
                return(true);
            }

            GeometryGraph      graph = new GeometryGraph(0, geom);
            LineIntersector    li    = new RobustLineIntersector();
            SegmentIntersector si    = graph.ComputeSelfNodes(li, true);

            // if no self-intersection, must be simple
            if (!si.HasIntersection)
            {
                return(true);
            }
            if (si.HasProperIntersection)
            {
                return(false);
            }
            if (HasNonEndpointIntersection(graph))
            {
                return(false);
            }
            if (HasClosedEndpointIntersection(graph))
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
        public static bool SegmentIntersects(Geometry g1, Geometry g2)
        {
            var pt1 = g1.Coordinates;
            var pt2 = g2.Coordinates;
            var ri  = new RobustLineIntersector();

            ri.ComputeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]);
            return(ri.HasIntersection);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="precisionModel"></param>
        /// <returns></returns>
        private static INoder GetNoder(PrecisionModel precisionModel)
        {
            // otherwise use a fast (but non-robust) noder
            LineIntersector li = new RobustLineIntersector();

            li.PrecisionModel = precisionModel;
            McIndexNoder noder = new McIndexNoder(new IntersectionAdder(li));

            return(noder);
        }
예제 #7
0
        /// <summary>
        /// Computes an intersection point between two segments, if there is one.
        /// There may be 0, 1 or many intersection points between two segments.
        /// If there are 0, null is returned. If there is 1 or more, a single one
        /// is returned (chosen at the discretion of the algorithm).  If
        /// more information is required about the details of the intersection,
        /// the {RobustLineIntersector} class should be used.
        /// </summary>
        /// <param name="line"></param>
        /// <returns> An intersection point, or <c>null</c> if there is none.</returns>
        public virtual Coordinate Intersection(ILineSegmentBase line)
        {
            LineIntersector li = new RobustLineIntersector();

            li.ComputeIntersection(P0, P1, new Coordinate(line.P0), new Coordinate(line.P1));
            if (li.HasIntersection)
            {
                return(li.GetIntersection(0));
            }
            return(null);
        }
예제 #8
0
        /// <summary>
        /// Computes an intersection point between two segments, if there is one.
        /// There may be 0, 1 or many intersection points between two segments.
        /// If there are 0, null is returned. If there is 1 or more, a single one
        /// is returned (chosen at the discretion of the algorithm).  If
        /// more information is required about the details of the intersection,
        /// the {RobustLineIntersector} class should be used.
        /// </summary>
        /// <param name="line">A line segment</param>
        /// <returns> An intersection point, or <c>null</c> if there is none.</returns>
        /// <see cref="RobustLineIntersector"/>
        public Coordinate Intersection(LineSegment line)
        {
            LineIntersector li = new RobustLineIntersector();

            li.ComputeIntersection(_p0, _p1, line._p0, line._p1);
            if (li.HasIntersection)
            {
                return(li.GetIntersection(0));
            }
            return(null);
        }
예제 #9
0
        public void TestCollinear4()
        {
            var i  = new RobustLineIntersector();
            var p1 = new Coordinate(30, 10);
            var p2 = new Coordinate(20, 10);
            var q1 = new Coordinate(10, 10);
            var q2 = new Coordinate(30, 10);

            i.ComputeIntersection(p1, p2, q1, q2);
            Assert.AreEqual(LineIntersector.CollinearIntersection, i.IntersectionNum);
            Assert.IsTrue(i.HasIntersection);
        }
        private void CheckIntersectionDir(LineSegment line1, LineSegment line2, Coordinate pt)
        {
            LineIntersector li = new RobustLineIntersector();

            li.ComputeIntersection(
                line1.P0, line1.P1,
                line2.P0, line2.P1);
            Assert.That(li.IntersectionNum, Is.EqualTo(1));
            var actual = li.GetIntersection(0);

            CheckEqualXYZ(pt, actual);
        }
예제 #11
0
        /// <summary>
        /// Checks validity of a LinearRing.
        /// </summary>
        /// <param name="g"></param>
        private void CheckValidRing(ILinearRing g)
        {
            CheckClosedRing(g);
            if (_validErr != null)
            {
                return;
            }
            GeometryGraph   graph = new GeometryGraph(0, g);
            LineIntersector li    = new RobustLineIntersector();

            graph.ComputeSelfNodes(li, true);
            CheckNoSelfIntersectingRings(graph);
        }
        public static Geometry MCIndexNodingWithPrecision(Geometry geom, double scaleFactor)
        {
            var fixedPM = new PrecisionModel(scaleFactor);

            LineIntersector li = new RobustLineIntersector();

            li.PrecisionModel = fixedPM;

            INoder noder = new MCIndexNoder(new IntersectionAdder(li));

            noder.ComputeNodes(SegmentStringUtil.ExtractNodedSegmentStrings(geom));
            return(SegmentStringUtil.ToGeometry(noder.GetNodedSubstrings(), geom.Factory));
        }
예제 #13
0
        private INoder CreateNoder(PrecisionModel precisionModel)
        {
            if (workingNoder != null)
                return workingNoder;
			
            // otherwise use a fast (but non-robust) noder
            MCIndexNoder noder       = new MCIndexNoder();
            LineIntersector li       = new RobustLineIntersector();
            li.PrecisionModel        = precisionModel;
            noder.SegmentIntersector = new IntersectionAdder(li);

            return noder;
        }
예제 #14
0
        public void TestCollinear3()
        {
            RobustLineIntersector i  = new RobustLineIntersector();
            Coordinate            p1 = new Coordinate(10, 10);
            Coordinate            p2 = new Coordinate(20, 10);
            Coordinate            q1 = new Coordinate(15, 10);
            Coordinate            q2 = new Coordinate(30, 10);

            i.ComputeIntersection(p1, p2, q1, q2);
            Assert.AreEqual(RobustLineIntersector.Collinear, i.IntersectionNum);
            Assert.IsTrue(!i.IsProper);
            Assert.IsTrue(i.HasIntersection);
        }
예제 #15
0
        public static IGeometry MCIndexNodingWithPrecision(Geometry geom, double scaleFactor)
        {
            List <ISegmentString> segs = CreateNodedSegmentStrings(geom);

            LineIntersector li = new RobustLineIntersector();

            li.PrecisionModel = new PrecisionModel(scaleFactor);
            INoder noder = new MCIndexNoder(new IntersectionAdder(li));

            noder.ComputeNodes(segs);
            IList <ISegmentString> nodedSegStrings = noder.GetNodedSubstrings();

            return(FromSegmentStrings(nodedSegStrings));
        }
        private void FindAndClassifyIntersections(IGeometry geom)
        {
            IList <ISegmentString> lineSegStr = SegmentStringUtil.ExtractSegmentStrings(geom);

            LineIntersector             li          = new RobustLineIntersector();
            SegmentIntersectionDetector intDetector = new SegmentIntersectionDetector(li);

            intDetector.FindAllIntersectionTypes = true;
            prepPoly.IntersectionFinder.Intersects(lineSegStr, intDetector);

            _hasSegmentIntersection   = intDetector.HasIntersection;
            _hasProperIntersection    = intDetector.HasProperIntersection;
            _hasNonProperIntersection = intDetector.HasNonProperIntersection;
        }
예제 #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="precisionModel"></param>
        /// <returns></returns>
        private INoder GetNoder(IPrecisionModel precisionModel)
        {
            if (workingNoder != null)
            {
                return(workingNoder);
            }

            // otherwise use a fast (but non-robust) noder
            LineIntersector li = new RobustLineIntersector();

            li.PrecisionModel = precisionModel;
            MCIndexNoder noder = new MCIndexNoder(new IntersectionAdder(li));

            return(noder);
        }
예제 #18
0
        private static INoder CreateFloatingPrecisionNoder(bool doValidation)
        {
            var mcNoder = new MCIndexNoder();
            var li      = new RobustLineIntersector();

            mcNoder.SegmentIntersector = new IntersectionAdder(li);

            INoder noder = mcNoder;

            if (doValidation)
            {
                noder = new ValidatingNoder(mcNoder);
            }
            return(noder);
        }
예제 #19
0
        public void Test2Lines()
        {
            var i  = new RobustLineIntersector();
            var p1 = new Coordinate(10, 10);
            var p2 = new Coordinate(20, 20);
            var q1 = new Coordinate(20, 10);
            var q2 = new Coordinate(10, 20);
            var x  = new Coordinate(15, 15);

            i.ComputeIntersection(p1, p2, q1, q2);
            Assert.AreEqual(LineIntersector.PointIntersection, i.IntersectionNum);
            Assert.AreEqual(1, i.IntersectionNum);
            Assert.AreEqual(x, i.GetIntersection(0));
            Assert.IsTrue(i.IsProper);
            Assert.IsTrue(i.HasIntersection);
        }
예제 #20
0
        public void Test2Lines()
        {
            RobustLineIntersector i  = new RobustLineIntersector();
            Coordinate            p1 = new Coordinate(10, 10);
            Coordinate            p2 = new Coordinate(20, 20);
            Coordinate            q1 = new Coordinate(20, 10);
            Coordinate            q2 = new Coordinate(10, 20);
            Coordinate            x  = new Coordinate(15, 15);

            i.ComputeIntersection(p1, p2, q1, q2);
            Assert.AreEqual(RobustLineIntersector.DoIntersect, i.IntersectionNum);
            Assert.AreEqual(1, i.IntersectionNum);
            Assert.AreEqual(x, i.GetIntersection(0));
            Assert.IsTrue(i.IsProper);
            Assert.IsTrue(i.HasIntersection);
        }
예제 #21
0
        /// <summary>
        /// Computes an intersection point between two segments, if there is one.
        /// </summary>
        /// <param name="">line
        /// </param>
        /// <returns> an intersection point, or null if there is none
        /// </returns>
        /// <remarks>
        /// There may be 0, 1 or many intersection points between two segments.
        /// If there are 0, null is returned. If there is 1 or more, a single one
        /// is returned (chosen at the discretion of the algorithm).  If
        /// more information is required about the details of the intersection,
        /// the <see cref="RobustLineIntersector"/> class should be used.
        /// </remarks>
        public Coordinate Intersection(LineSegment line)
        {
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }

            LineIntersector li = new RobustLineIntersector();

            li.ComputeIntersection(p0, p1, line.p0, line.p1);
            if (li.HasIntersection)
            {
                return(li.GetIntersection(0));
            }

            return(null);
        }
예제 #22
0
        public static Geometry SegmentIntersectionDd(Geometry g1, Geometry g2)
        {
            var pt1 = g1.Coordinates;
            var pt2 = g2.Coordinates;

            // first check if there actually is an intersection
            var ri = new RobustLineIntersector();

            ri.ComputeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]);
            if (!ri.HasIntersection)
            {
                // no intersection => return empty point
                return(g1.Factory.CreatePoint((Coordinate)null));
            }

            var intPt = CGAlgorithmsDD.Intersection(pt1[0], pt1[1], pt2[0], pt2[1]);

            return(g1.Factory.CreatePoint(intPt));
        }
        public void CheckInputNotAltered(Coordinate[] pt, int scaleFactor)
        {
            // save input points
            Coordinate[] savePt = new Coordinate[4];
            for (int i = 0; i < 4; i++)
            {
                savePt[i] = new Coordinate(pt[i]);
            }

            LineIntersector li = new RobustLineIntersector();

            li.PrecisionModel = new PrecisionModel(scaleFactor);
            li.ComputeIntersection(pt[0], pt[1], pt[2], pt[3]);

            // check that input points are unchanged
            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(savePt[i], pt[i], "Input point " + i + " was altered - ");
            }
        }
        /// <summary>
        /// Check that intersection of segment defined by points in pt array
        /// is equal to the expectedIntPt value (up to the given distanceTolerance)
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="expectedIntersectionNum"></param>
        /// <param name="expectedIntPt">the expected intersection points (maybe null if not tested)</param>
        /// <param name="distanceTolerance">tolerance to use for equality test</param>
        private void CheckIntersection(Coordinate[] pt,
                                       int expectedIntersectionNum,
                                       Coordinate[] expectedIntPt,
                                       double distanceTolerance)
        {
            LineIntersector li = new RobustLineIntersector();

            li.ComputeIntersection(pt[0], pt[1], pt[2], pt[3]);

            int intNum = li.IntersectionNum;

            Assert.AreEqual(expectedIntersectionNum, intNum, "Number of intersections not as expected");

            if (expectedIntPt != null)
            {
                Assert.AreEqual(intNum, expectedIntPt.Length, "Wrong number of expected int pts provided");
                // test that both points are represented here
                if (intNum == 1)
                {
                    CheckIntPoints(expectedIntPt[0], li.GetIntersection(0), distanceTolerance);
                }
                else if (intNum == 2)
                {
                    CheckIntPoints(expectedIntPt[1], li.GetIntersection(0), distanceTolerance);
                    CheckIntPoints(expectedIntPt[1], li.GetIntersection(0), distanceTolerance);

                    if (!(Equals(expectedIntPt[0], li.GetIntersection(0), distanceTolerance) ||
                          Equals(expectedIntPt[0], li.GetIntersection(1), distanceTolerance)))
                    {
                        CheckIntPoints(expectedIntPt[0], li.GetIntersection(0), distanceTolerance);
                        CheckIntPoints(expectedIntPt[0], li.GetIntersection(1), distanceTolerance);
                    }
                    else if (!(Equals(expectedIntPt[1], li.GetIntersection(0), distanceTolerance) ||
                               Equals(expectedIntPt[1], li.GetIntersection(1), distanceTolerance)))
                    {
                        CheckIntPoints(expectedIntPt[1], li.GetIntersection(0), distanceTolerance);
                        CheckIntPoints(expectedIntPt[1], li.GetIntersection(1), distanceTolerance);
                    }
                }
            }
        }
        private void CheckIntersectionDir(LineSegment line1, LineSegment line2, Coordinate p1, Coordinate p2)
        {
            LineIntersector li = new RobustLineIntersector();

            li.ComputeIntersection(
                line1.P0, line1.P1,
                line2.P0, line2.P1);

            Assert.That(li.IntersectionNum, Is.EqualTo(2));

            var actual1 = li.GetIntersection(0);
            var actual2 = li.GetIntersection(1);

            // normalize actual results
            if (actual1.CompareTo(actual2) > 0)
            {
                actual1 = li.GetIntersection(1);
                actual2 = li.GetIntersection(0);
            }

            CheckEqualXYZ(p1, actual1);
            CheckEqualXYZ(p2, actual2);
        }
예제 #26
0
        private void AddIntersections()
        {
            var seqA = GetVertices(_geomA);
            var seqB = GetVertices(_geomB);

            // NTS-specific: these arrays were only written to, never read from.
            ////bool[] isIntersected0 = new bool[seqA.Count - 1];
            ////bool[] isIntersected1 = new bool[seqB.Count - 1];

            bool isCCWA = Orientation.IsCCW(seqA);
            bool isCCWB = Orientation.IsCCW(seqB);

            // Compute rays for all intersections
            var li = new RobustLineIntersector();

            for (int i = 0; i < seqA.Count - 1; i++)
            {
                var a0 = seqA.GetCoordinate(i);
                var a1 = seqA.GetCoordinate(i + 1);

                if (isCCWA)
                {
                    // flip segment orientation
                    (a0, a1) = (a1, a0);
                }

                for (int j = 0; j < seqB.Count - 1; j++)
                {
                    var b0 = seqB.GetCoordinate(j);
                    var b1 = seqB.GetCoordinate(j + 1);

                    if (isCCWB)
                    {
                        // flip segment orientation
                        (b0, b1) = (b1, b0);
                    }

                    li.ComputeIntersection(a0, a1, b0, b1);
                    if (li.HasIntersection)
                    {
                        // NTS-specific: these arrays were only written to, never read from.
                        ////isIntersected0[i] = true;
                        ////isIntersected1[j] = true;

                        /*
                         * With both rings oriented CW (effectively)
                         * There are two situations for segment intersections:
                         *
                         * 1) A entering B, B exiting A => rays are IP-A1:R, IP-B0:L
                         * 2) A exiting B, B entering A => rays are IP-A0:L, IP-B1:R
                         * (where :L/R indicates result is to the Left or Right).
                         *
                         * Use full edge to compute direction, for accuracy.
                         */
                        var intPt = li.GetIntersection(0);

                        bool isAenteringB = OrientationIndex.CounterClockwise == Orientation.Index(a0, a1, b1);

                        if (isAenteringB)
                        {
                            _area += EdgeRay.AreaTerm(intPt, a0, a1, true);
                            _area += EdgeRay.AreaTerm(intPt, b1, b0, false);
                        }
                        else
                        {
                            _area += EdgeRay.AreaTerm(intPt, a1, a0, false);
                            _area += EdgeRay.AreaTerm(intPt, b0, b1, true);
                        }
                    }
                }
            }
        }
예제 #27
0
		} // public bool IsSimple( MultiPoint mp )

		/// <summary>
		/// Tests to see if geometry is simple.
		/// </summary>
		/// <param name="geom">Geometry to test.</param>
		/// <returns>Returns true if geometry is simple, false otherwise.</returns>
		private bool IsSimpleLinearGeometry( Geometry geom )
		{
			if( geom.IsEmpty() )
			{
				return true;
			}
			GeometryGraph graph = new GeometryGraph( 0, geom );
			LineIntersector li = new RobustLineIntersector();
			SegmentIntersector si = graph.ComputeSelfNodes( li );
			// if no self-intersection, must be simple
			if( !si.HasIntersection )
			{
				return true;
			}
			if( si.HasProperIntersection )
			{
				return false;
			}
			if( HasNonEndpointIntersection( graph ) )
			{
				return false;
			}
			if( HasClosedEndpointIntersection( graph ) )
			{
				return false;
			}
			return true;
		} // private bool IsSimpleLinearGeometry( Geometry geom )