码迷,mamicode.com
首页 > Web开发 > 详细

[NetTopologySuite](2)任意多边形求交

时间:2015-06-08 23:15:15      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

任意多边形求交:

技术分享
 private void btnPolygon_Click(object sender, EventArgs e)
        {

            double[] Xs = new double[] { 30, 260, 130, 350, 250, 330, 320, 180, 250, 50, 70, 60, 30, 260 };
            double[] Ys = new double[] { 140, 260, 110, 150, 230, 210, 140, 260 };
            int m = Xs.Length / 2;
            var coords = new Coordinate[m];
            var coordscheck = new Coordinate[m];
            for (var i = 0; i < Xs.Length / 2; i++)
            {
                var x = Xs[i * 2];
                var y = Xs[i * 2 + 1];
                coords[i] = new Coordinate(x, y);
                coordscheck[i] = new Coordinate(x, y);
            }
            // Shell Rings
            var ring = new LinearRing(coords);
            var gf = new GeometryFactory();
            var ringCheck = gf.CreateLinearRing(coordscheck);
            // Hole Coordinates
            int n = Ys.Length / 2;
            var coordsholecheck = new Coordinate[n];
            var coordshole = new Coordinate[n];
            for (var i = 0; i < Ys.Length / 2; i++)
            {
                var x = Ys[i * 2];
                var y = Ys[i * 2 + 1];
                coordshole[i] = new Coordinate(x, y);
                coordsholecheck[i] = new Coordinate(x, y);
            }
            // Hole LinearRing Arrays
            var hole = new LinearRing(coordshole);
            var holes = new ILinearRing[1];
            var holeCheck = gf.CreateLinearRing(coordsholecheck);
            var holescheck = new ILinearRing[1];
            holes[0] = hole;
            holescheck[0] = holeCheck;
            Polygon pg = new Polygon(ring, holes);//
            var polygonCheck = gf.CreatePolygon(ringCheck, holescheck);
            var areaCheck = polygonCheck.Area;
            var area = pg.Area;
            //
            inputGeometry = pg;


            double[] XsAnalysis = new double[] { 210, 390, 180, 290, 170, 210, 190, 140, 360, 60, 470, 220, 440, 390 };
            double[] YsAnalysis = new double[] { 340, 310, 250, 260, 270, 140, 360, 130, 390, 230, 340, 310 };
            m = XsAnalysis.Length / 2;
            var coordsAnalysis = new Coordinate[m];
            var coordscheckAnalysis = new Coordinate[m];
            for (var i = 0; i < XsAnalysis.Length / 2; i++)
            {
                var x = XsAnalysis[i * 2];
                var y = XsAnalysis[i * 2 + 1];
                coordsAnalysis[i] = new Coordinate(x, y);
                coordscheckAnalysis[i] = new Coordinate(x, y);
            }
            // Shell Rings
            var ringAnalysis = new LinearRing(coordsAnalysis);
            var gfAnalysis = new GeometryFactory();
            var ringCheckAnalysis = gfAnalysis.CreateLinearRing(coordscheckAnalysis);
            // Hole Coordinates
            n = YsAnalysis.Length / 2;
            var coordsholecheckAnalysis = new Coordinate[n];
            var coordsholeAnalysis = new Coordinate[n];
            for (var i = 0; i < YsAnalysis.Length / 2; i++)
            {
                var x = YsAnalysis[i * 2];
                var y = YsAnalysis[i * 2 + 1];
                coordsholeAnalysis[i] = new Coordinate(x, y);
                coordsholecheckAnalysis[i] = new Coordinate(x, y);
            }
            // Hole LinearRing Arrays
            var holeAnalysis = new LinearRing(coordsholeAnalysis);
            var holesAnalysis = new ILinearRing[1];
            var holeCheckAnalysis = gf.CreateLinearRing(coordsholecheckAnalysis);
            var holescheckAnalysis = new ILinearRing[1];
            holesAnalysis[0] = holeAnalysis;
            holescheckAnalysis[0] = holeCheckAnalysis;
            Polygon pgAnalysis = new Polygon(ringAnalysis, holesAnalysis);//
            var polygonCheckAnalysis = gf.CreatePolygon(ringCheckAnalysis, holescheckAnalysis);
            var areaCheckAnalysis = polygonCheckAnalysis.Area;
            var areaAnalysis = pgAnalysis.Area;
            //
            AnalysisPolygonGeometry = pgAnalysis;


            intersectionOutput = AnalysisPolygonGeometry.Intersection(inputGeometry);
            this.Invalidate();
        }
View Code

技术分享

[NetTopologySuite](2)任意多边形求交

标签:

原文地址:http://www.cnblogs.com/yhlx125/p/4562097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!