流程示意图
示例代码
using GeoAPI.Geometries;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using System.Collections.Generic;
using System.Linq;namespace Test472
{[TestClass]public class TestEnvelope{[TestMethod]public void TestEnvelopeUnion(){//创建一下用于测试的点var pts = new List<Point>(){new Point(0,0),new Point(0.9,1),new Point(1.2,1.5),new Point(2,-0.5),new Point(1.2,-1),};var circles= pts.Select(x => x.Buffer(0.5));var envelopes = polygons.Select(x => GeometryFactory.Default.ToGeometry(x.EnvelopeInternal));//Shp.Save("./circles.shp", circles);//输出几何,为了查看效果//Shp.Save("./envelopes.shp", envelopes);//输出几何,为了查看效果var envelope = Union(polygons);var unionEnvelopeGeo= GeometryFactory.Default.ToGeometry(envelope);//Shp.Save("./envelope.shp", unionEnvelopeGeo);//输出几何,为了查看效果}//合并所有几何的包围盒public static Envelope Union(IEnumerable<IGeometry> geos){var result = new Envelope();foreach (var geom in geos){if (geom is null){continue;}result.ExpandToInclude(geom.EnvelopeInternal);}return result;}}
}
- 如果是1.X版本,则使用上面的Union函数。
- 如果是2.X版本,则可以直接使用封装好的类:
EnvelopeCombiner
。
叠加效果图: