流程示意圖
示例代碼
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
。
疊加效果圖: