/// <summary> /// Since polygons from countries and cells 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)) && (openPolygonsCount == 0 || (openPolygonsCount == 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 of that if (maxPoints < 0) { return(null); } // Polygon polygon = new Polygon (); // Contour c = new Contour (); // c.AddRange (largestPointChain.pointList); // polygon.AddContour (c); // FixOrientation (polygon); tempContour.Clear(); tempContour.AddRange(largestPointChain.pointList); tempPolygon.Clear(); tempPolygon.AddContour(tempContour); FixOrientation(tempPolygon); return(tempPolygon); }
public Polygon ToPolygon() { // 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; } Polygon polygon = new Polygon (); foreach (PointChain pointChain in closedPolygons) { Contour c = new Contour (); c.AddRange (pointChain.pointList); polygon.AddContour (c); } FixOrientation(polygon); return polygon; }
public Polygon ToPolygon() { // Check for empty result if ((closedPolygons.Count == 0 || (closedPolygons.Count == 1 && closedPolygons [0].pointList.Count == 0)) && (openPolygonsCount == 0 || (openPolygonsCount == 1 && openPolygons [0].pointList.Count == 0))) { return(null); } Polygon polygon = new Polygon(); foreach (PointChain pointChain in closedPolygons) { Contour c = new Contour(); c.AddRange(pointChain.pointList); polygon.AddContour(c); } FixOrientation(polygon); return(polygon); }
/// <summary> /// Since polygons from countries and cells 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 of that if (maxPoints<0) return null; Polygon polygon = new Polygon (); Contour c = new Contour (); c.AddRange (largestPointChain.pointList); polygon.AddContour (c); FixOrientation(polygon); return polygon; }