Engine 中IGeometryCollection接口

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;
            }
        }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值