zoukankan      html  css  js  c++  java
  • union Itoplogicaloperator(很难)

    如何调用ITopologicalOperator.Union方法成功地merge polygon 收藏

    为什么题目要加个“成功地”,因为ITopologicalOperator的方法是bug非常多的,在90%的情况下能够按照你预想的工作,但是在10%的情况下,既不报错也不工作。这个merge的操作,成功地折磨了我两天。终于找到了解决的方法。
          ICursor pCursor;
          featureSelect.SelectionSet.Search(
    nullfalseout 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);
            pFeatureNext.Delete();

            pFeatureNext 
    = pFeatureCursor.NextFeature();
          }

          topo_oper.IsKnownSimple_2 
    = false;
          topo_oper.Simplify();
          pFeatureFirst.Shape 
    = pGeometryFirst;
          pFeatureFirst.Store();
          m_EditWorkspace.StopEditOperation();
  • 相关阅读:
    JS自动微信消息轰炸
    会议管家——常用的JQ知识点
    关于微信分享
    前端——解决微信网页清除缓存的方法
    2018新知识点
    一键分享代码(提供能分享到QQ空间、新浪微博、人人网等的分享功能)
    如何在网中使用百度地图API自定义个性化地图
    spring5 源码深度解析----- IOC 之 默认标签解析(上)
    spring5 源码深度解析----- IOC 之 容器的基本实现
    高级Java工程师必备 ----- 深入分析 Java IO (三)
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1428347.html
Copyright © 2011-2022 走看看