在多面体上进行并集时,Clipperlib的行为不正常

时间:2015-09-05 20:44:23

标签: c# computational-geometry geojson clipperlib

我正在尝试合并多边形,但效果不佳,如下图所示:

enter image description here

我使用的代码是:

using ClipperLib;
using Polygon = System.Collections.Generic.List<ClipperLib.IntPoint>;
using Polygons = System.Collections.Generic.List<System.Collections.Generic.List<ClipperLib.IntPoint>>;

namespace Ylp.ComputationalGeometry
{
    public static class Merge
    {
        public static IList<IList<double>> Multipolygon(IList<IList<IList<IList<double>>>> multiPolygon)
        {
            const double precisionFactor = 1000000000000000.0;

            //precondition: all your polygons have the same orientation 
            //(ie either clockwise or counter clockwise)
            Polygons polys = new Polygons();

            multiPolygon.ForEach(x =>
            {
                Polygon polygon = x.First().Select( y => new IntPoint()
                {
                    X = (long)(y[0] * precisionFactor),
                    Y = (long)(y[1] * precisionFactor)
                }).ToList();

                polys.Add(polygon);
            });

            Polygons solution = new Polygons();
            Clipper c = new Clipper();
            c.AddPaths(polys, PolyType.ptSubject,true);
            c.Execute(ClipType.ctUnion, solution,
                PolyFillType.pftNonZero, PolyFillType.pftNonZero);

            var coordinates = solution.SelectMany(x => x.Select(y=> (IList<double>)new List<double>()
            {
                y.X / precisionFactor,
                y.Y / precisionFactor
            }).ToList()) .ToList();

            return coordinates;
        }
    }
}

我真正希望工会的结果看起来像下面这样,所以中间的任何交叉都应该被忽略,并且应该创建一个覆盖两个形状的区域:

enter image description here

原始形状是: enter image description here

0 个答案:

没有答案