Exemple #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);
        }
Exemple #2
0
        public Polygon ToPolygon()
        {
            // Check for empty result
            if ((closedPolygons.Count == 0 ||
                 (closedPolygons.Count == 1 && closedPolygons[0].pointList.Count < 5)) &&
                (openPolygons.Count == 0 ||
                 (openPolygons.Count == 1 && openPolygons[0].pointList.Count < 5)))
            {
                return(null);
            }

            Polygon polygon = new Polygon();

            foreach (PointChain pointChain in closedPolygons)
            {
                if (pointChain.pointList.Count >= 5)
                {
                    Contour c = new Contour();
                    c.AddRange(pointChain.pointList);
                    polygon.AddContour(c);
                }
            }
            FixOrientation(polygon);
            return(polygon);
        }
Exemple #3
0
        public PolygonClipper(Region regionSubject, Region regionClipping)
        {
            // Setup subject and clipping polygons
            this.regionSubject = regionSubject;

            subject = new Polygon();
            Contour scont = new Contour();

            scont.AddRange(regionSubject.latlon);
            int scontCount = scont.points.Count;

            for (int k = 0; k < scontCount; k++)
            {
                scont.points[k] *= PRECISION;
            }
            subject.AddContour(scont);

            clipping = new Polygon();
            Contour ccont = new Contour();

            ccont.AddRange(regionClipping.latlon);
            int ccontCount = ccont.points.Count;

            for (int k = 0; k < ccontCount; k++)
            {
                ccont.points[k] *= PRECISION;
            }
            clipping.AddContour(ccont);

            // Init event queue
            eventQueue = new EventQueue();
        }
        public Polygon Clone()
        {
            Polygon poly = new Polygon();

            foreach (Contour cont in this.contours)
            {
                Contour c = new Contour();
                c.AddRange(cont.points);
                poly.AddContour(c);
            }
            return(poly);
        }
Exemple #5
0
        public PolygonClipper(Region regionSubject)
        {
            // Setup subject and clipping polygons
            this.regionSubject = regionSubject;

            subject = new Polygon();
            Contour scont = new Contour();

            scont.AddRange(regionSubject.latlon);
            int scontCount = scont.points.Count;

            for (int k = 0; k < scontCount; k++)
            {
                scont.points[k] *= PRECISION;
            }
            subject.AddContour(scont);
        }
Exemple #6
0
        public void SetClippingRegion(Region regionClipping)
        {
            clipping = new Polygon();
            Contour ccont = new Contour();

            ccont.AddRange(regionClipping.latlon);
            int ccontCount = ccont.points.Count;

            for (int k = 0; k < ccontCount; k++)
            {
                ccont.points[k] *= PRECISION;
            }
            clipping.AddContour(ccont);

            // Init event queue
            eventQueue = new EventQueue();
        }