Ejemplo n.º 1
0
        /// <summary>
        /// Since polygons from countries and provinces are not perfectly aligned in all cases, this method will take the largest contour and assume this is the resulting polygon
        /// (even if it's not closed...)
        /// </summary>
        public Polygon ToPolygonFromLargestLineStrip()
        {
            // Check for empty result
            if ((closedPolygons.Count == 0 ||
                 (closedPolygons.Count == 1 && closedPolygons[0].pointList.Count == 0)) &&
                (openPolygons.Count == 0 ||
                 (openPolygons.Count == 1 && openPolygons[0].pointList.Count == 0)))
            {
                return(null);
            }

            // Get the largest contour (open or closed)
            int        maxPoints         = -1;
            PointChain largestPointChain = null;

            foreach (PointChain pointChain in closedPolygons)
            {
                if (pointChain.pointList.Count > maxPoints)
                {
                    maxPoints         = pointChain.pointList.Count;
                    largestPointChain = pointChain;
                }
            }
            foreach (PointChain pointChain in openPolygons)
            {
                if (pointChain.pointList.Count > maxPoints)
                {
                    maxPoints         = pointChain.pointList.Count;
                    largestPointChain = pointChain;
                }
            }

            // ... and create a new polygon from that
            if (maxPoints < 0)
            {
                return(null);
            }
            Polygon polygon = new Polygon();
            Contour contour = new Contour();

            contour.AddRange(largestPointChain.pointList);
            polygon.AddContour(contour);

            // add other closed polygons
            foreach (PointChain pointChain in closedPolygons)
            {
                if (largestPointChain != pointChain)
                {
                    Contour otherContour = new Contour();
                    otherContour.AddRange(pointChain.pointList);
                    if (!contour.Contains(otherContour))
                    {
                        polygon.AddContour(otherContour);
                    }
                }
            }

            FixOrientation(polygon);
            return(polygon);
        }
Ejemplo n.º 2
0
        bool PolyInPoly(Contour outer, Contour inner)
        {
            int innerPointCount = inner.points.Count;

            for (int p = 0; p < innerPointCount; p++)
            {
                if (!outer.Contains(inner.points[p]))
                {
                    return(false);
                }
            }
            return(true);
        }