예제 #1
0
        /// <summary>
        /// This routine checks to see if a shell is properly contained in a hole.
        /// It assumes that the edges of the shell and hole do not
        /// properly intersect.
        /// </summary>
        /// <param name="shell"></param>
        /// <param name="hole"></param>
        /// <param name="graph"></param>
        /// <returns>
        /// <c>null</c> if the shell is properly contained, or
        /// a Coordinate which is not inside the hole if it is not.
        /// </returns>
        private Coordinate CheckShellInsideHole(ILinearRing shell, ILinearRing hole, GeometryGraph graph)
        {
            Coordinate[] shellPts = shell.Coordinates;
            Coordinate[] holePts  = hole.Coordinates;
            // TODO: improve performance of this - by sorting pointlists?
            Coordinate shellPt = FindPointNotNode(shellPts, hole, graph);

            // if point is on shell but not hole, check that the shell is inside the hole
            if (shellPt != null)
            {
                bool insideHole = PointLocation.IsInRing(shellPt, holePts);
                if (!insideHole)
                {
                    return(shellPt);
                }
            }
            Coordinate holePt = FindPointNotNode(holePts, shell, graph);

            // if point is on hole but not shell, check that the hole is outside the shell
            if (holePt != null)
            {
                bool insideShell = PointLocation.IsInRing(holePt, shellPts);
                if (insideShell)
                {
                    return(holePt);
                }
                return(null);
            }
            Assert.ShouldNeverReachHere("points in shell and hole appear to be equal");
            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool IsNonNested()
        {
            foreach (var innerRing in rings)
            {
                var innerRingPts = innerRing.Coordinates;

                foreach (var searchRing in rings)
                {
                    var searchRingPts = searchRing.Coordinates;

                    if (innerRing == searchRing)
                    {
                        continue;
                    }

                    if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal))
                    {
                        continue;
                    }

                    var innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph);
                    Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring");

                    bool isInside = PointLocation.IsInRing(innerRingPt, searchRingPts);
                    if (isInside)
                    {
                        nestedPt = innerRingPt;
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
        /// The innermost enclosing ring is the <i>smallest</i> enclosing ring.
        /// The algorithm used depends on the fact that:
        /// ring A contains ring B iff envelope(ring A) contains envelope(ring B).
        /// This routine is only safe to use if the chosen point of the hole
        /// is known to be properly contained in a shell
        /// (which is guaranteed to be the case if the hole does not touch its shell).
        /// </summary>
        /// <param name="testEr"></param>
        /// <param name="shellList"></param>
        /// <returns>Containing EdgeRing, if there is one <br/> or
        /// <value>null</value> if no containing EdgeRing is found.</returns>
        private static EdgeRing FindEdgeRingContaining(EdgeRing testEr, IEnumerable <EdgeRing> shellList)
        {
            var teString = testEr.LinearRing;
            var testEnv  = teString.EnvelopeInternal;
            var testPt   = teString.GetCoordinateN(0);

            EdgeRing minShell = null;
            Envelope minEnv   = null;

            foreach (var tryShell in shellList)
            {
                var tryRing = tryShell.LinearRing;
                var tryEnv  = tryRing.EnvelopeInternal;
                if (minShell != null)
                {
                    minEnv = minShell.LinearRing.EnvelopeInternal;
                }
                bool isContained = false;
                if (tryEnv.Contains(testEnv) && PointLocation.IsInRing(testPt, tryRing.Coordinates))
                {
                    isContained = true;
                }
                // check if this new containing ring is smaller than the current minimum ring
                if (isContained)
                {
                    if (minShell == null || minEnv.Contains(tryEnv))
                    {
                        minShell = tryShell;
                    }
                }
            }
            return(minShell);
        }
예제 #4
0
 public void test1()
 {
     Assert.IsTrue(PointLocation.IsOnLine(new Coordinate(10, 10),
                                          new Coordinate[] { new Coordinate(0, 10), new Coordinate(20, 10) }));
     Assert.IsTrue(!PointLocation.IsOnLine(new Coordinate(30, 10),
                                           new Coordinate[] { new Coordinate(0, 10), new Coordinate(20, 10) }));
 }
        private void CheckOnLine(double x, double y, string wktLine, bool expected)
        {
            var line = (LineString)this.Read(wktLine);

            Assert.That(PointLocation.IsOnLine(new Coordinate(x, y), line.Coordinates), Is.EqualTo(expected));
            Assert.That(PointLocation.IsOnLine(new Coordinate(x, y), line.CoordinateSequence), Is.EqualTo(expected));
        }
예제 #6
0
 private void InitCurrentSegment(PointLocation start)
 {
     CurrentSegment = new SegmentLocation()
     {
         Start = start
     };
 }
        void CheckOnLine(double x, double y, string wktLine, bool expected)
        {
            var line = (LineString)Read(wktLine);

            Assert.AreEqual(expected, PointLocation.IsOnLine(new Coordinate(x, y), line.Coordinates));
            Assert.AreEqual(expected, PointLocation.IsOnLine(new Coordinate(x, y), line.CoordinateSequence));
        }
예제 #8
0
 public PointInfo(GENERIC_SYSTEM_PARAMETERS.POINTS.POINT point, string pos, string orient, PointLocation src, IInfo srcI)
 {
     this.ptSrc    = src;
     this.Point    = point;
     this.position = pos;
     this.orient   = orient;
     this.srcStr   = srcI;
     check();
 }
 ///<summary>
 /// Determines whether a point lies in a LinearRing, using the ring envelope to short-circuit if possible.
 ///</summary>
 /// <param name="p">The point to test</param>
 /// <param name="ring">A linear ring</param>
 /// <returns><c>true</c> if the point lies inside the ring</returns>
 private static Location LocatePointInRing(Coordinate p, ILinearRing ring)
 {
     // short-circuit if point is not in ring envelope
     if (!ring.EnvelopeInternal.Intersects(p))
     {
         return(Location.Exterior);
     }
     return(PointLocation.LocateInRing(p, ring.CoordinateSequence));
 }
예제 #10
0
        private void FinCurrentSegment(PointLocation end)
        {
            var endOffset = Math.Max(Text.IndexOf('\n', end.Offset), end.Offset);

            CurrentSegment.End = new PointLocation(
                end.Line,
                end.Column + endOffset - end.Offset,
                endOffset
                );
        }
예제 #11
0
        public void SetLocation(PointLocation start, PointLocation end)
        {
            _location = new SegmentLocation()
            {
                Start = start,
                End   = end
            };

            LocationReady = true;
        }
예제 #12
0

        
예제 #13
0
        public bool IsNonNested()
        {
            BuildIndex();

            for (int i = 0; i < _rings.Count; i++)
            {
                var          innerRing    = (ILinearRing)_rings[i];
                Coordinate[] innerRingPts = innerRing.Coordinates;

                var results = _index.Query(innerRing.EnvelopeInternal);
                for (int j = 0; j < results.Count; j++)
                {
                    var searchRing    = (ILinearRing)results[j];
                    var searchRingPts = searchRing.Coordinates;

                    if (innerRing == searchRing)
                    {
                        continue;
                    }

                    if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal))
                    {
                        continue;
                    }

                    Coordinate innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, _graph);
                    // Diego Guidi: removed => see Issue 121
                    //Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring");

                    /**
                     * If no non-node pts can be found, this means
                     * that the searchRing touches ALL of the innerRing vertices.
                     * This indicates an invalid polygon, since either
                     * the two holes create a disconnected interior,
                     * or they touch in an infinite number of points
                     * (i.e. along a line segment).
                     * Both of these cases are caught by other tests,
                     * so it is safe to simply skip this situation here.
                     */
                    if (innerRingPt == null)
                    {
                        continue;
                    }

                    Boolean isInside = PointLocation.IsInRing(innerRingPt, searchRingPts);
                    if (isInside)
                    {
                        _nestedPt = innerRingPt;
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #14
0
 static IEnumerable <CdtTriangle> FindStartTriangle(CdtTriangle[] trs, Point p)
 {
     foreach (CdtTriangle t in trs)
     {
         PointLocation loc = CdtIntersections.PointLocationInsideTriangle(p, t);
         if (loc != PointLocation.Outside)
         {
             yield return(t);
         }
     }
 }
예제 #15
0
        public void TestA()
        {
            var p1 = new Coordinate(-123456789, -40);
            var p2 = new Coordinate(381039468754763d, 123456789);
            var q  = new Coordinate(0, 0);
            var l  = new GeometryFactory().CreateLineString(new Coordinate[] { p1, p2 });
            var p  = new GeometryFactory().CreatePoint(q);

            Assert.AreEqual(false, l.Intersects(p));
            Assert.AreEqual(false, PointLocation.IsOnLine(q, new Coordinate[] { p1, p2 }));
            Assert.AreEqual(OrientationIndex.Clockwise, Orientation.Index(p1, p2, q));
        }
예제 #16
0
        /// <summary>
        /// Tests whether the point pt is contained in the triangle defined by 3 <see cref="QuadEdge"/>es.
        /// </summary>
        /// <param name="tri">an array containing at least 3 QuadEdges</param>
        /// <param name="pt">the point to test</param>
        /// <returns>true if the point is contained in the triangle</returns>
        public static bool Contains(QuadEdge[] tri, Coordinate pt)
        {
            var ring = new[]
            {
                tri[0].Orig.Coordinate,
                tri[1].Orig.Coordinate,
                tri[2].Orig.Coordinate,
                tri[0].Orig.Coordinate
            };

            return(PointLocation.IsInRing(pt, ring));
        }
예제 #17
0
        protected override void RunPtInRing(Location expectedLoc, Coordinate pt, string wkt)
        {
            var geom = reader.Read(wkt);

            Assert.AreEqual(expectedLoc, PointLocation.LocateInRing(pt, geom.Coordinates));
            var poly = geom as Polygon;

            if (poly == null)
            {
                return;
            }

            Assert.AreEqual(expectedLoc, PointLocation.LocateInRing(pt, poly.ExteriorRing.CoordinateSequence));
        }
예제 #18
0
 private void SafeGrammarAction(Action action, PointLocation loc)
 {
     try
     {
         action();
     }
     catch (IncorrectGrammarException ex)
     {
         Log.Add(Message.Error(
                     ex.Message,
                     loc,
                     "LanD"
                     ));
     }
 }
예제 #19
0
        public PointLocation GetPointLocation(Point point, out Point edgeStart, out Point edgeEnd)
        {
            PolylinePoint start;

            edgeStart = new Point();
            edgeEnd   = new Point();
            PointLocation loc = GetPointLocation(point, out start);

            if (PointLocation.Boundary == loc)
            {
                edgeStart = start.Point;
                edgeEnd   = start.NextOnPolyline.Point;
            }
            return(loc);
        }
예제 #20
0
        /// <summary>
        /// Check if a shell is incorrectly nested within a polygon.  This is the case
        /// if the shell is inside the polygon shell, but not inside a polygon hole.
        /// (If the shell is inside a polygon hole, the nesting is valid.)
        /// The algorithm used relies on the fact that the rings must be properly contained.
        /// E.g. they cannot partially overlap (this has been previously checked by
        /// <c>CheckRelateConsistency</c>).
        /// </summary>
        private void CheckShellNotNested(ILinearRing shell, IPolygon p, GeometryGraph graph)
        {
            Coordinate[] shellPts = shell.Coordinates;
            // test if shell is inside polygon shell
            ILinearRing polyShell = p.Shell;

            Coordinate[] polyPts = polyShell.Coordinates;
            Coordinate   shellPt = FindPointNotNode(shellPts, polyShell, graph);

            // if no point could be found, we can assume that the shell is outside the polygon
            if (shellPt == null)
            {
                return;
            }
            bool insidePolyShell = PointLocation.IsInRing(shellPt, polyPts);

            if (!insidePolyShell)
            {
                return;
            }
            // if no holes, this is an error!
            if (p.NumInteriorRings <= 0)
            {
                _validErr = new TopologyValidationError(TopologyValidationErrors.NestedShells, shellPt);
                return;
            }

            /*
             * Check if the shell is inside one of the holes.
             * This is the case if one of the calls to checkShellInsideHole
             * returns a null coordinate.
             * Otherwise, the shell is not properly contained in a hole, which is an error.
             */
            Coordinate badNestedPt = null;

            for (int i = 0; i < p.NumInteriorRings; i++)
            {
                ILinearRing hole = p.Holes[i];
                badNestedPt = CheckShellInsideHole(shell, hole, graph);
                if (badNestedPt == null)
                {
                    return;
                }
            }
            _validErr = new TopologyValidationError(TopologyValidationErrors.NestedShells, badNestedPt);
        }
        /// <summary>
        /// Computes the intersection between the hub and obstacles
        /// </summary>
        /// <param name="node"></param>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="obstaclesToIgnore">these are the obstacles the are ignored by the method</param>
        /// <param name="touchedObstacles">list of pairs (obstacle, closest point on the obstacle)</param>
        /// <param name="minimalDistance">min distance from the center to an obstacle</param>
        /// <returns>false iff center is inside of an obstacle</returns>
        static bool IntersectCircleWithTree(RectangleNode <Polyline, Point> node, Point center, double radius, Set <Polyline> obstaclesToIgnore,
                                            List <Tuple <Polyline, Point> > touchedObstacles, ref double minimalDistance)
        {
            if (!node.Rectangle.Contains(center, radius))
            {
                return(true);
            }

            if (node.UserData == null)
            {
                bool res = IntersectCircleWithTree(node.Left, center, radius, obstaclesToIgnore, touchedObstacles, ref minimalDistance);
                if (!res)
                {
                    return(false);
                }
                res = IntersectCircleWithTree(node.Right, center, radius, obstaclesToIgnore, touchedObstacles, ref minimalDistance);
                if (!res)
                {
                    return(false);
                }
            }
            else
            {
                Polyline obstacle = node.UserData;
                if (obstaclesToIgnore.Contains(obstacle))
                {
                    return(true);
                }

                PointLocation pl = Curve.PointRelativeToCurveLocation(center, obstacle);
                if (pl != PointLocation.Outside)
                {
                    return(false);
                }

                Point  touchPoint = obstacle[obstacle.ClosestParameter(center)];
                double dist       = (touchPoint - center).Length;
                if (dist <= radius)
                {
                    touchedObstacles.Add(new Tuple <Polyline, Point>(obstacle, touchPoint));
                }
                minimalDistance = Math.Min(dist, minimalDistance);
            }
            return(true);
        }
예제 #22
0
        /// <summary>
        /// Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
        /// The innermost enclosing ring is the <i>smallest</i> enclosing ring.
        /// The algorithm used depends on the fact that:
        /// ring A contains ring B iff envelope(ring A) contains envelope(ring B).
        /// This routine is only safe to use if the chosen point of the hole
        /// is known to be properly contained in a shell
        /// (which is guaranteed to be the case if the hole does not touch its shell).
        /// </summary>
        /// <param name="shellList"></param>
        /// <param name="testEr"></param>
        /// <returns>Containing EdgeRing, if there is one <br/>
        /// or <value>null</value> if no containing EdgeRing is found.</returns>
        public static EdgeRing FindEdgeRingContaining(EdgeRing testEr, IList <EdgeRing> shellList)
        {
            var testRing = testEr.Ring;
            var testEnv  = testRing.EnvelopeInternal;
            //var testPt = testRing.GetCoordinateN(0);

            EdgeRing minShell    = null;
            Envelope minShellEnv = null;

            foreach (var tryShell in shellList)
            {
                var tryShellRing = tryShell.Ring;
                var tryShellEnv  = tryShellRing.EnvelopeInternal;
                if (minShell != null)
                {
                    minShellEnv = minShell.Ring.EnvelopeInternal;
                }

                // the hole envelope cannot equal the shell envelope
                // (also guards against testing rings against themselves)
                if (tryShellEnv.Equals(testEnv))
                {
                    continue;
                }
                // hole must be contained in shell
                if (!tryShellEnv.Contains(testEnv))
                {
                    continue;
                }

                var testPt      = CoordinateArrays.PointNotInList(testRing.Coordinates, tryShellRing.Coordinates);
                var isContained = PointLocation.IsInRing(testPt, tryShellRing.Coordinates);

                // check if this new containing ring is smaller than the current minimum ring
                if (isContained)
                {
                    if (minShell == null || minShellEnv.Contains(tryShellEnv))
                    {
                        minShell    = tryShell;
                        minShellEnv = minShell.Ring.EnvelopeInternal;
                    }
                }
            }
            return(minShell);
        }
        /// <summary>
        /// Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any.
        /// The innermost enclosing ring is the <i>smallest</i> enclosing ring.
        /// The algorithm used depends on the fact that:
        /// ring A contains ring B iff envelope(ring A) contains envelope(ring B).
        /// This routine is only safe to use if the chosen point of the hole
        /// is known to be properly contained in a shell
        /// (which is guaranteed to be the case if the hole does not touch its shell).
        /// </summary>
        /// <param name="testEr"></param>
        /// <param name="shellList"></param>
        /// <returns>Containing EdgeRing, if there is one <br/> or
        /// <c>null</c> if no containing EdgeRing is found.</returns>
        private static EdgeRing FindEdgeRingContaining(EdgeRing testEr, IEnumerable <EdgeRing> shellList)
        {
            var teString = testEr.LinearRing;
            var testEnv  = teString.EnvelopeInternal;
            var testPt   = teString.GetCoordinateN(0);

            EdgeRing minShell    = null;
            Envelope minShellEnv = null;

            foreach (var tryShell in shellList)
            {
                var tryShellRing = tryShell.LinearRing;
                var tryShellEnv  = tryShellRing.EnvelopeInternal;
                // the hole envelope cannot equal the shell envelope
                // (also guards against testing rings against themselves)
                if (tryShellEnv.Equals(testEnv))
                {
                    continue;
                }
                // hole must be contained in shell
                if (!tryShellEnv.Contains(testEnv))
                {
                    continue;
                }

                bool isContained = false;
                if (PointLocation.IsInRing(testPt, tryShellRing.Coordinates))
                {
                    isContained = true;
                }

                // check if this new containing ring is smaller than the current minimum ring
                if (isContained)
                {
                    if (minShell == null || minShellEnv.Contains(tryShellEnv))
                    {
                        minShell    = tryShell;
                        minShellEnv = tryShellEnv;
                    }
                }
            }
            return(minShell);
        }
예제 #24
0
        /// <summary>
        /// Circle Plot Algorithm
        /// 1. Using parametric equation of a circle
        ///    x = h + rcos(t)
        ///    y = k + rsin(t)
        ///    where t is theter:- angle subtended by the point at the center of the circle
        ///    NOTE: t is in radians
        ///    h is the center cordinate of the circle on the x-axis
        ///    k is the center cordinate of the circle on the y asxis
        ///    r is the radius of the circle
        /// 2. Assume h,k and r
        /// 3. Select an change or step for t
        /// 4. Applying the above will provide corresponding x and y cordinates
        /// </summary>
        /// <param name="x_center_cordinate"></param>
        /// <param name="y_center_cordinate"></param>
        /// <param name="radius"></param>
        /// <param name="thetaIntervalRadians"> thetaIntervalRadians = (2*Math.PI)/(No of points you need)</param>
        /// <returns></returns>
        public List <PointLocation> ComputePointsForCirclePlot(int x_center_cordinate, int y_center_cordinate, int radius, double thetaIntervalRadians)
        {
            int    h          = x_center_cordinate;
            int    k          = y_center_cordinate;
            int    r          = radius;
            double theta_step = thetaIntervalRadians;
            double pi         = Math.PI;
            List <PointLocation> pointLocations = new List <PointLocation>();

            for (double theta = 0; theta < (2 * pi); theta += theta_step)
            {
                PointLocation pointLocation = new PointLocation();
                double        x             = h + (r * Math.Cos(theta));
                double        y             = k + (r * Math.Sin(theta));
                pointLocation.X = (float)x;
                pointLocation.Y = (float)y;
                pointLocations.Add(pointLocation);
            }
            return(pointLocations);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="innerRing"></param>
        /// <param name="searchRing"></param>
        /// <returns></returns>
        private bool IsInside(LinearRing innerRing, LinearRing searchRing)
        {
            var innerRingPts  = innerRing.Coordinates;
            var searchRingPts = searchRing.Coordinates;

            if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal))
            {
                return(false);
            }
            var innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph);

            Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring");
            bool isInside = PointLocation.IsInRing(innerRingPt, searchRingPts);

            if (isInside)
            {
                nestedPt = innerRingPt;
                return(true);
            }
            return(false);
        }
        protected override void RunPtInRing(Location expectedLoc, Coordinate pt, string wkt)
        {
            // isPointInRing is not defined for pts on boundary
            if (expectedLoc == Location.Boundary)
            {
                return;
            }

            var  geom     = reader.Read(wkt);
            bool expected = expectedLoc == Location.Interior;

            Assert.AreEqual(expected, PointLocation.IsInRing(pt, geom.Coordinates));
            var poly = geom as IPolygon;

            if (poly == null)
            {
                return;
            }

            Assert.AreEqual(expected, PointLocation.IsInRing(pt, poly.ExteriorRing.CoordinateSequence));
        }
예제 #27
0
        /// <summary>
        /// This method will cause the ring to be computed.
        /// It will also check any holes, if they have been assigned.
        /// </summary>
        /// <param name="p"></param>
        public bool ContainsPoint(Coordinate p)
        {
            ILinearRing shell = LinearRing;
            Envelope    env   = shell.EnvelopeInternal;

            if (!env.Contains(p))
            {
                return(false);
            }
            if (!PointLocation.IsInRing(p, shell.Coordinates))
            {
                return(false);
            }
            foreach (EdgeRing hole in _holes)
            {
                if (hole.ContainsPoint(p))
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool IsNonNested()
        {
            BuildQuadtree();

            for (int i = 0; i < _rings.Count; i++)
            {
                var innerRing    = _rings[i];
                var innerRingPts = innerRing.Coordinates;

                var results = _quadtree.Query(innerRing.EnvelopeInternal);
                for (int j = 0; j < results.Count; j++)
                {
                    var searchRing    = results[j];
                    var searchRingPts = searchRing.Coordinates;

                    if (innerRing == searchRing)
                    {
                        continue;
                    }

                    if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal))
                    {
                        continue;
                    }

                    var innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, _graph);
                    Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring");

                    bool isInside = PointLocation.IsInRing(innerRingPt, searchRingPts);
                    if (isInside)
                    {
                        _nestedPt = innerRingPt;
                        return(false);
                    }
                }
            }
            return(true);
        }
 private void cboLoc_SelectedIndexChanged2(object sender, EventArgs e)
 {
     loc = (PointLocation)Enum.Parse(typeof(PointLocation), lstLoc[cboLoc.SelectedIndex], true);
     #if (PocketPC || WindowsCE || Mobile)
     btnLoc.Text = loc.ToString();
     #endif
 }
 private void btnLoc_Click2(object sender, EventArgs e)
 {
     using (Selection form = new Selection("Point Location", lstLoc, lstLoc.IndexOf(loc.ToString())))
     {
         if (form.ShowDialog() == DialogResult.OK)
         {
             loc = (PointLocation)Enum.Parse(typeof(PointLocation), lstLoc[form.selection], true);
             btnLoc.Text = loc.ToString();
             cboLoc.SelectedIndex = form.selection;
         }
     }
 }
        public void Init()
        {
            this.Icon = Properties.Resources.Map;
            this.DialogResult = DialogResult.Cancel;

            _killThread = false;

            #if (PocketPC || WindowsCE || Mobile)
            if (Values.Settings.DeviceOptions.UseSelection)
            {
                btnDist.Visible = true;
                btnLoc.Visible = true;
                btnPoly.Visible = true;
                btnStart.Visible = true;
                btnSample.Visible = true;

                cboDist.Visible = false;
                cboLoc.Visible = false;
                cboPoly.Visible = false;
                cboSample.Visible = false;
                cboStart.Visible = false;
            }
            else
            {
                btnDist.Visible = false;
                btnLoc.Visible = false;
                btnPoly.Visible = false;
                btnStart.Visible = false;
                btnSample.Visible = false;

                cboDist.Visible = true;
                cboLoc.Visible = true;
                cboPoly.Visible = true;
                cboSample.Visible = true;
                cboStart.Visible = true;
            }
            #endif

            ix = 100;
            iy = 100;
            delOld = true;
            tilt = null;

            lstPoly = new List<string>();
            lstDist = new List<string>();
            lstLoc = new List<string>();

            _Polys = DAL.GetPolygons();

            if (_Polys.Count < 1)
            {
                MessageBox.Show("");
                this.DialogResult = DialogResult.Abort;
            }
            else
            {
                foreach (TtPolygon poly in _Polys)
                {
                    cboPoly.Items.Add(poly.Name);
                    lstPoly.Add(poly.Name);
                }

                ChangePoly(_Polys[0].CN);

                lstLoc.Add(PointLocation.Inside.ToString());
                lstLoc.Add(PointLocation.Extents.ToString());

                cboLoc.Items.Add(PointLocation.Inside);
                cboLoc.Items.Add(PointLocation.Extents);

                lstDist.Add(Unit.FEET_TENTH.ToString());
                lstDist.Add(Unit.METERS.ToString());
                //lstDist.Add(Unit.FEET_INCHES.ToString());
                //lstDist.Add(Unit.YARDS.ToString());
                lstDist.Add(Unit.CHAINS.ToString());

                cboDist.Items.Add(Unit.FEET_TENTH);
                cboDist.Items.Add(Unit.METERS);
                //cboDist.Items.Add(Unit.FEET_INCHES);
                //cboDist.Items.Add(Unit.YARDS);
                cboDist.Items.Add(Unit.CHAINS);

                cboLoc.SelectedIndex = 0;
                cboDist.SelectedIndex = 0;
                cboPoly.SelectedIndex = 0;

                dist = Unit.FEET_TENTH;
                PolyCN = _Polys[0].CN;
                loc = PointLocation.Inside;

            #if (PocketPC || WindowsCE || Mobile)
                btnPoly.Text = lstPoly[0];
                btnLoc.Text = loc.ToString();
                btnDist.Text = dist.ToString();
            #endif
                sType = SampleType.Percent;

                cboSample.Items.Add(SampleType.Percent.ToString());
                cboSample.Items.Add(SampleType.Points.ToString());

            #if (PocketPC || WindowsCE || Mobile)
                cboSample.SelectedIndex = 0;
                btnSample.Text = sType.ToString();
            #endif

                DoSample = false;
                chkSample.Checked = DoSample;

                SampleAmt = 100;
                txtSample.Text = SampleAmt.ToString();
                _generated = false;

                if (Values.FormPlotLastPolyIndex > -1)
                    cboPoly.SelectedIndex = Values.FormPlotLastPolyIndex;
                if (Values.FormPlotLastStartIndex > -1)
                    cboStart.SelectedIndex = Values.FormPlotLastStartIndex;
                if (Values.FormPlotLastDistIndex > -1)
                    cboDist.SelectedIndex = Values.FormPlotLastDistIndex;
                if (Values.FormPlotLastLocIndex > -1)
                    cboLoc.SelectedIndex = Values.FormPlotLastLocIndex;
                if (Values.FormPlotLastGrid1Val > 0)
                    txti1.Text = Values.FormPlotLastGrid1Val.ToString();
                if (Values.FormPlotLastGrid2Val > 0)
                    txti2.Text = Values.FormPlotLastGrid2Val.ToString();
                if (Values.FormPlotLastTiltVal > 0)
                    txtTilt.Text = Values.FormPlotLastTiltVal.ToString();

                if (Values.FormPlotLastSampleIndex > -1)
                    cboSample.SelectedIndex = Values.FormPlotLastSampleIndex;
                if (Values.FormPlotLastSampleVal > 0)
                    txtSample.Text = Values.FormPlotLastSampleVal.ToString();
            }
        }
예제 #32
0
        private void ReadPolygonShape(Shape shape)
        {
            List <LinearRing> shells = new();
            List <LinearRing> holes  = new();

            foreach (PartRange part in shape.Range.Parts)
            {
                List <Coordinate> coords = new();
                int i = part.StartIndex;
                foreach (Vertex d in part)
                {
                    Coordinate c = new(d.X, d.Y);
                    if (shape.M != null && shape.M.Length > 0)
                    {
                        c.M = shape.M[i];
                    }
                    if (shape.Z != null && shape.Z.Length > 0)
                    {
                        c.Z = shape.Z[i];
                    }
                    i++;
                    coords.Add(c);
                }

                LinearRing ring = new(coords.ToArray());
                if (shape.Range.Parts.Count == 1)
                {
                    shells.Add(ring);
                }
                else
                {
                    if (ring.IsCCW)
                    {
                        holes.Add(ring);
                    }
                    else
                    {
                        shells.Add(ring);
                    }
                }
            }

            if (shells.Count == 0 && holes.Count > 0)
            {
                shells = holes;
                holes  = new List <LinearRing>();
            }

            //// Now we have a list of all shells and all holes
            List <LinearRing>[] holesForShells = new List <LinearRing> [shells.Count];
            for (int i = 0; i < shells.Count; i++)
            {
                holesForShells[i] = new List <LinearRing>();
            }

            // Find holes
            foreach (LinearRing hole in holes)
            {
                LinearRing minShell = null;
                Envelope   minEnv   = null;
                Envelope   testEnv  = hole.EnvelopeInternal;
                Coordinate testPt   = hole.Coordinates[0];
                for (int j = 0; j < shells.Count; j++)
                {
                    LinearRing tryRing = shells[j];
                    Envelope   tryEnv  = tryRing.EnvelopeInternal;
                    if (minShell != null)
                    {
                        minEnv = minShell.EnvelopeInternal;
                    }

                    // Check if this new containing ring is smaller than the current minimum ring
                    if (tryEnv.Contains(testEnv) && (PointLocation.IsInRing(testPt, tryRing.Coordinates) || PointInList(testPt, tryRing.Coordinates)))
                    {
                        if (minShell == null || minEnv.Contains(tryEnv))
                        {
                            minShell = tryRing;
                        }

                        holesForShells[j].Add(hole);
                    }
                }
            }

            var polygons = new Polygon[shells.Count];

            for (int i = 0; i < shells.Count; i++)
            {
                polygons[i] = new Polygon(shells[i], holesForShells[i].ToArray());
            }

            if (polygons.Length == 1)
            {
                _geometry = polygons[0];
            }
            else
            {
                // It's a multi part
                _geometry = new MultiPolygon(polygons);
            }

            _featureType = FeatureType.Polygon;
        }
예제 #33
0
        public bool Contains(Coordinate pt)
        {
            var ring = GetCoordinates();

            return(PointLocation.IsInRing(pt, ring));
        }