Example #1
0
        /// <summary>
        /// Tests that each hole is inside the polygon shell.
        /// This routine assumes that the holes have previously been tested
        /// to ensure that all vertices lie on the shell or inside it.
        /// A simple test of a single point in the hole can be used,
        /// provide the point is chosen such that it does not lie on the
        /// boundary of the shell.
        /// </summary>
        /// <param name="p">The polygon to be tested for hole inclusion.</param>
        /// <param name="graph">A GeometryGraph incorporating the polygon.</param>
        private void CheckHolesInShell(IPolygon p, GeometryGraph graph)
        {
            ILinearRing shell = p.Shell;

            IPointInRing pir = new MCPointInRing(shell);

            for (int i = 0; i < p.NumInteriorRings; i++)
            {
                ILinearRing hole   = p.Holes[i];
                ICoordinate holePt = FindPointNotNode(hole.Coordinates, shell, graph);

                /*
                 * If no non-node hole vertex can be found, the hole must
                 * split the polygon into disconnected interiors.
                 * This will be caught by a subsequent check.
                 */
                if (holePt == null)
                {
                    return;
                }

                bool outside = !pir.IsInside((Coordinate)holePt);
                if (outside)
                {
                    validErr = new TopologyValidationError(TopologyValidationErrors.HoleOutsideShell, holePt);
                    return;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Test that each hole is inside the polygon shell.
        /// This routine assumes that the holes have previously been tested
        /// to ensure that all vertices lie on the shell or inside it.
        /// A simple test of a single point in the hole can be used,
        /// provide the point is chosen such that it does not lie on the
        /// boundary of the shell.
        /// </summary>
        /// <param name="p">The polygon to be tested for hole inclusion.</param>
        /// <param name="graph">Graph a GeometryGraph incorporating the polygon.</param>
        private void CheckHolesInShell(Polygon p, GeometryGraph graph)
        {
            LinearRing  shell    = (LinearRing)p.GetExteriorRing();
            Coordinates shellPts = shell.GetCoordinates();

            //PointInRing pir = new SimplePointInRing(shell);
            //PointInRing pir = new SIRtreePointInRing(shell);
            IPointInRing pir = new MCPointInRing(shell);

            for (int i = 0; i < p.GetNumInteriorRing(); i++)
            {
                LinearRing hole   = (LinearRing)p.GetInteriorRingN(i);
                Coordinate holePt = FindPtNotNode(hole.GetCoordinates(), shell, graph);
                if (holePt == null)
                {
                    throw new InvalidOperationException("Unable to find a hole point not a vertex of the shell.");
                }

                bool outside = !pir.IsInside(holePt);
                if (outside)
                {
                    _validErr = new TopologyValidationError(
                        TopologyValidationError.HoleOutsideShell,
                        holePt);
                    return;
                }
            }
        }
Example #3
0
        protected override void RunPtInRing(Location expectedLoc, Coordinate pt, String wkt)
        {
            // isPointInRing is not defined for pts on boundary
            if (expectedLoc == Location.Boundary)
            {
                return;
            }

            IGeometry geom = reader.Read(wkt);

            if (!(geom is Polygon))
            {
                return;
            }

            LinearRing    ring     = (LinearRing)((Polygon)geom).ExteriorRing;
            bool          expected = expectedLoc == Location.Interior;
            MCPointInRing pir      = new MCPointInRing(ring);
            bool          result   = pir.IsInside(pt);

            Assert.AreEqual(expected, result);
        }