Geometry 集合接口

IGeometryCollection
 

IGeometryCollection 接口被 Polygon,Polyline, Multipoint, Multipatch, Trangle,Trangle Strip,Trangle Fan 和 GeometryBag 所实现。


 

Geometry 属性
通过一个索引值返回一个组成该几何对象的某个子对象。

GeometryCount 属性

返回组成该几何对象的子对象的数目。

AddGeometry 方法
向一个几何对象添加一个几何对象,将子对象添加到几何的指定索引值的位置。

AddGeometries 方法
向一个几何对象添加多个几何对象,将子对象数组添加到集合的最后。

在使用 AddGeometry 方法添加子对象到 Polygon 对象的过程中,如果子对象即 Ring 出现覆盖现象,那么多边形就没有封闭或出现了包含关系,那么这个 Polygon 就不是简单 Polygon,因此通过 IGometryCollection 来创建一个 Polygon 时,需要使用 ITopologicalOperator 的 Simplify 方法保证其有效性

private IPolygon ConstructorPolygon(List<IRing> pRingList)
{
	try
	{
		IGeometryCollection pGCollection = new PolygonClass();
		object o = Type.Missing;

		for (int i = 0; i < pRingList.Count; i++)
		{
			// 通过IGeometryCollection接口的AddGeometry方法向Polygon对象中添加Ring子对象
			pGCollection.AddGeometry(pRingList[i], ref o, ref o);
		}

		// QI至ITopologicalOperator
		ITopologicalOperator pTopological = pGCollection as ITopologicalOperator;
		
		// 执行Simplify操作
		pTopological.Simplify();

		IPolygon pPolygon = pGCollection as IPolygon;
		//返回Polygon对象
		return pPolygon;
	}
	catch (Exception Err)
	{
		return null;
	}
}
private IPolygon MergePolygons(IPolygon FirstPolygon, IPolygon SecondPolygon)
{
	try
	{
		// 创建一个Polygon对象
		IGeometryCollection pGCollection1 = new PolygonClass();
		IGeometryCollection pGCollection2 = FirstPolygon as IGeometryCollection;
		IGeometryCollection pGCollection3 = SecondPolygon as IGeometryCollection;

		// 添加FirstPolygon
		pGCollection1.AddGeometryCollection(pGCollection2);
		// 添加SecondPolygon
		pGCollection1.AddGeometryCollection(pGCollection3);

		// QI至ITopologicalOperator
		ITopologicalOperator pTopological = pGCollection1 as ITopologicalOperator;
		// 执行Simplify操作
		pTopological.Simplify();

		//返回Polygon对象
		IPolygon pPolygon = pGCollection1 as IPolygon;
		return pPolygon;
	}
	catch (Exception Err)
	{
		return null;
	}
}


ISegmentCollection

 

ISegmentCollection 接口被 Path, Ring, Polyline 和 Polygon 四个类实现。


IPointCollection
ISegmentCollection 可以被多个几个对象类所实现,如 Multipoint, Path, Ring, Polyline, Polygon, Trangle,Trangle Strip,Trangle Fan, Multipatch.