Geometry
IGeometryCollection的Geometry 属性可以通过一个索引值返回一个组成该几何对象的某个子对象,GeometryCount返回组成该几何对象的子对象的数目。
IGeometry中
AddGeometry;添加一个几何对象,可以将子对象添加到几何的指定索引值的位置
AddGeometries:添加一个几何对象数组,将子对象数组添加到集合的最后
在使用AddGeometry方法添加子对象到Polygon对象的过程中,如果子对象即Ring出现覆盖现象,
那么多边形就没有封闭或出现了包含关系,那么这个Polygon就不是简单Polygon,因此通过
IGometryCollection来创建一个Polygon时,需要使用ITopologicalOperator 的Simplify方法保证其有
效性。
IGeometryCollection接口
通过IGeometryCollection创建一个Polygon对象的代码片段如下:
Polygon 是由Ring组成
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对象
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;
}
}
Polygon 的合并 方法1
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();
IPolygon pPolygon = pGCollection1 as IPolygon;
//返回Polygon对象
return pPolygon;
}
catch (Exception Err)
{
return null;
}
}
Polygon 的合并 方法2
private IPolygon ConstructorPolygon(List<IPolygon > pPolygonList)
{
try
{
IGeometryCollection pGCollection = new PolygonClass();
object o = Type.Missing;
for (int i = 0; i < pPolygonList).Count; i++)
{
//通过IGeometryCollection接口的AddGeometry方法向Polygon对象
pGCollection.AddGeometry( pPolygonList[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;
}
}