ITopologicalOperator接口使用方法

时间:2022-01-23 14:58:53

在空间分析中通常用到ITopologicalOperator接口,有众多的空间拓扑方法,在GIS系统中的缓冲区分析、裁剪分析、几何图形差分操作、几何图形合并操作等等。下面介绍ITopologicalOperator接口的主要方法:

http://www.cnblogs.com/alex-bn-lee/archive/2012/06/17/2552557.html#ITopologicalOperator5

ITopologicalOperator接口使用方法


但是这个接口出现问题的几率是非常大的,有时候既没有报错,但是有没有运行出结果,比如Union、merge方法,其实是在我们做拓扑之前的检查不够。导致出现这个问题。下面给出示例代码:

    ICursor pCursor;  
      
    featureSelect.SelectionSet.Search(null, false, out pCursor);  
      
      
      
    IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;  
      
    IFeature pFeatureFirst = pFeatureCursor.NextFeature();  
      
      
      
    // 开始一个编辑操作,以能够撤销  
      
    m_EditWorkspace.StartEditOperation();  
      
      
      
    IGeometry pGeometryFirst = pFeatureFirst.Shape;  
      
    ITopologicalOperator2 topo_oper = (ITopologicalOperator2)pGeometryFirst;  
      
      
      
    //ITopologicalOperator的操作是bug很多的,先强制的检查下面三个步骤,再进行操作  否则会出现标题所说的问题
      
    topo_oper.IsKnownSimple_2 = false;        //处理之前不知道是否是简单多边形,不管是不是,第一步强制转换为非简单多边形
      
    topo_oper.Simplify();                     //对多边形强制简单化
      
    pGeometryFirst.SnapToSpatialReference();  //图形与坐标参考对应 
      
      
      
    //这是准备合并的图斑使用的  
      
    ITopologicalOperator2 topo_oper2;  
      
    IGeometry pGeometryNext;  
      
    IFeature pFeatureNext = pFeatureCursor.NextFeature();  
      
      
      
    while (pFeatureNext != null)  
      
    {  
      
      pGeometryNext = pFeatureNext.ShapeCopy;  
      
      
      
      //与上面的同理  
      
      topo_oper2 = pGeometryNext as ITopologicalOperator2;  
      
      topo_oper2.IsKnownSimple_2 = false;  
      
      topo_oper2.Simplify();  
      
      pGeometryNext.SnapToSpatialReference();  
      
      
      
      //这才是合并图斑的关键  
      
      pGeometryFirst = topo_oper.Union(pGeometryNext);  
      
      topo_oper = pGeometryFirst  as ITopologicalOperator2;  
      
      pFeatureNext.Delete();  
      
      
      
      pFeatureNext = pFeatureCursor.NextFeature();  
      
    }  
      
    topo_oper.IsKnownSimple_2 = false;  
      
    topo_oper.Simplify();  
      
    pFeatureFirst.Shape = pGeometryFirst;  
      
    pFeatureFirst.Store();  
      
    m_EditWorkspace.StopEditOperation();