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

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(); }
作者:太一吾鱼水
文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。
欢迎大家留言交流,转载请注明出处。
分类:
图形学 & GIS算法
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
2012-06-08 ENVI处理Modis数据学习