Beispiel #1
0
        //规则添加工具
        private void PRV_AddRuleTool(ITopologyRule IN_TopologyRule, string idname)
        {
            ITopologyRuleContainer Temp_TopologyRuleContainer = (ITopologyRuleContainer)Topology;//构建容器

            try
            {
                Temp_TopologyRuleContainer.get_CanAddRule(IN_TopologyRule);//不能添加的话直接报错
                try
                {
                    Temp_TopologyRuleContainer.DeleteRule(IN_TopologyRule); //删除已存在的规则后再添加
                    IN_TopologyRule.OriginSubtype = int.Parse(idname);
                    Temp_TopologyRuleContainer.AddRule(IN_TopologyRule);    //规则存在的话直接报错
                }
                catch
                {
                    Temp_TopologyRuleContainer.AddRule(IN_TopologyRule);
                }
            }
            catch
            {
                MessageBox.Show("不支持添加");
            }
            // PRV_ValidateTopologyWithGP();//添加完成后自动检验
            //PUB_GetTopoLayer();//存储创建的拓扑图层

            //PRV_GetError(IN_TopologyRule);//输出错误
        }
Beispiel #2
0
        //规则添加工具
        private void PRV_AddRuleTool(ITopologyRule IN_TopologyRule)
        {
            ITopologyRuleContainer Temp_TopologyRuleContainer = (ITopologyRuleContainer)Topology;//构建容器

            try
            {
                Temp_TopologyRuleContainer.get_CanAddRule(IN_TopologyRule);//不能添加的话直接报错
                try
                {
                    Temp_TopologyRuleContainer.DeleteRule(IN_TopologyRule); //删除已存在的规则后再添加
                    Temp_TopologyRuleContainer.AddRule(IN_TopologyRule);    //规则存在的话直接报错
                }
                catch
                {
                    Temp_TopologyRuleContainer.AddRule(IN_TopologyRule);
                }
            }
            catch
            {
                MessageBox.Show("不支持添加");
            }
            PRV_ValidateTopologyWithGP();  //添加完成后自动检验
            PUB_GetTopoLayer();            //存储创建的拓扑图层
            PRV_GetError(IN_TopologyRule); //输出错误
        }
 public void Apply()
 {
     if (this.bool_0)
     {
         int num;
         this.bool_0 = false;
         ITopologyRuleContainer container = this.itopology_0 as ITopologyRuleContainer;
         for (num = 0; num < this.ilist_0.Count; num++)
         {
             container.DeleteRule(this.ilist_0[num] as ITopologyRule);
         }
         this.ilist_0.Clear();
         for (num = this.listView1.Items.Count - 1; num >= 0; num--)
         {
             ListViewItem item = this.listView1.Items[num];
             if ((item.Tag as Class2).IsNew && container.get_CanAddRule((item.Tag as Class2).TopoRule))
             {
                 try
                 {
                     container.AddRule((item.Tag as Class2).TopoRule);
                     (item.Tag as Class2).IsNew = false;
                 }
                 catch (Exception exception)
                 {
                     Logger.Current.Error("", exception, "");
                 }
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// 添加拓扑规则条件
        /// </summary>
        /// <param name="topology">拓扑对象</param>
        /// <param name="ruleType">规则类型</param>
        /// <param name="ruleName">规则名称</param>
        /// <param name="featureClass">要素类</param>
        private void AddRuleToTopology(ITopology topology, esriTopologyRuleType ruleType, String ruleName, IFeatureClass featureClass)
        {
            try
            {
                // Create a topology rule.
                ITopologyRule topologyRule = new TopologyRuleClass();
                topologyRule.TopologyRuleType  = ruleType;
                topologyRule.Name              = ruleName;
                topologyRule.OriginClassID     = featureClass.FeatureClassID;
                topologyRule.AllOriginSubtypes = true;

                // Cast the topology to the ITopologyRuleContainer interface and add the rule.
                ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology;
                if (topologyRuleContainer.get_CanAddRule(topologyRule))
                {
                    topologyRuleContainer.AddRule(topologyRule);
                }
                else
                {
                    throw new ArgumentException("Could not add specified rule to the topology.");
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #5
0
        public void AddRuleToTopology2(ITopology topology, esriTopologyRuleType ruleType, String ruleName, IFeatureClass originClass, int originSubtype, IFeatureClass destinationClass, int destinationSubtype)
        {
            // Create a topology rule.
            ITopologyRule topologyRule = new TopologyRuleClass();

            topologyRule.TopologyRuleType  = ruleType;
            topologyRule.Name              = ruleName;
            topologyRule.OriginClassID     = originClass.FeatureClassID;
            topologyRule.AllOriginSubtypes = true;
            //topologyRule.OriginSubtype = originSubtype;
            topologyRule.DestinationClassID     = destinationClass.FeatureClassID;
            topologyRule.AllDestinationSubtypes = true;
            //topologyRule.DestinationSubtype = destinationSubtype;

            // Cast the topology to the ITopologyRuleContainer interface and add the rule.
            ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology;

            if (topologyRuleContainer.get_CanAddRule(topologyRule))
            {
                topologyRuleContainer.AddRule(topologyRule);
            }
            else
            {
                throw new ArgumentException("Could not add specified rule to the topology.");
            }
        }
Beispiel #6
0
        /// <summary>
        /// 为要素类添加拓扑规则,针对针对特殊的要素类检查
        /// </summary>
        /// <param name="pTopo">拓扑</param>
        /// <param name="pTopoRuleType">拓扑规则</param>
        /// <param name="outError">异常</param>
        public void AddRuletoTopology(ITopology pTopo, esriTopologyRuleType pTopoRuleType, out Exception outError)
        {
            outError = null;

            try
            {
                ITopologyRuleContainer pRuleContainer   = pTopo as ITopologyRuleContainer;
                IFeatureClassContainer pFeaClsContainer = pTopo as IFeatureClassContainer;
                IEnumFeatureClass      pEnumFeaCls      = pFeaClsContainer.Classes;
                pEnumFeaCls.Reset();
                IFeatureClass pFeaCls = pEnumFeaCls.Next();

                //设置拓扑规则
                while (pFeaCls != null)
                {
                    ITopologyRule pTopoRule = new TopologyRuleClass();
                    pTopoRule.TopologyRuleType  = pTopoRuleType;
                    pTopoRule.Name              = (pFeaCls as IDataset).Name;
                    pTopoRule.OriginClassID     = pFeaCls.FeatureClassID;
                    pTopoRule.AllOriginSubtypes = true;
                    pRuleContainer.AddRule(pTopoRule);
                    pFeaCls = pEnumFeaCls.Next();
                }
            }
            catch (Exception ex)
            {
                ////*********************************************
                ////guozheng 2010-12-24 平安夜  added 系统异常日志
                //if (ModData.SysLog == null) ModData.SysLog = new clsWriteSystemFunctionLog();
                //ModData.SysLog.Write(ex);
                ////**********************************************
                outError = ex;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 添加单要素拓扑规则
        /// </summary>
        /// <param name="topology">建立的拓扑</param>
        /// <param name="FeatureClassName1">要素的名称</param>
        /// <param name="TopoRule">拓扑规则中文描述</param>
        private void AddTopoRules(ITopology topology, string FeatureClassName1, string TopoRule)
        {
            IFeatureClass        pFeatureClass1 = getFeatureClassByName(FeatureClassName1, pFeatureClassList);
            esriTopologyRuleType RuleType       = getTopoRuleByDescription(TopoRule);

            //创建拓扑规则
            ITopologyRule pTopoRule = new TopologyRuleClass();

            pTopoRule.OriginClassID    = pFeatureClass1.FeatureClassID;
            pTopoRule.TopologyRuleType = RuleType;

            //这两个参数应该设置为true,否则生成的拓扑没有东西
            pTopoRule.AllDestinationSubtypes = true;
            pTopoRule.AllOriginSubtypes      = true;

            ITopologyRuleContainer pTopologyRuleContainer = topology as ITopologyRuleContainer;

            if (pTopologyRuleContainer.CanAddRule[pTopoRule])
            {
                pTopologyRuleContainer.AddRule(pTopoRule);
            }
            else
            {
                throw new ArgumentException("无法添加" + pFeatureClass1.AliasName + "-" + pTopoRule.Name + "!");
            }
        }
Beispiel #8
0
        /// <summary>
        /// 添加拓扑规则
        /// </summary>
        /// <param name="topology"></param>
        /// <param name="topologyRule"></param>
        public static void AddRuleToTopology(this ITopology topology, ITopologyRule topologyRule)
        {
            ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology;//构建容器

            try
            {
                topologyRuleContainer.get_CanAddRule(topologyRule);//不能添加的话直接报错
                try
                {
                    topologyRuleContainer.DeleteRule(topologyRule); //删除已存在的规则后再添加
                    topologyRuleContainer.AddRule(topologyRule);    //规则存在的话直接报错
                }
                catch
                {
                    topologyRuleContainer.AddRule(topologyRule);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("不支持添加拓扑规则:" + ex.Message);
            }
        }
        public void Beat()
        {
            IWorkspace      workspace      = ArcClass.GetmdbWorkspace(mdbFilePath);
            IFeatureDataset featureDataset = ArcClass.GetFeatureDataset(workspace, "WJL");

            if (featureDataset != null)
            {
                ITopologyContainer     topologyContainer     = featureDataset as ITopologyContainer;
                ITopology              topology              = topologyContainer.CreateTopology("result", topologyContainer.DefaultClusterTolerance, -1, "");
                IFeatureClassContainer featureClassContainer = featureDataset as IFeatureClassContainer;
                IFeatureClass          featureClass          = featureClassContainer.get_ClassByName("Roads");
                topology.AddClass(featureClass, 5, 1, 1, false);
                ITopologyRuleContainer topologyRuleContainer = topology as ITopologyRuleContainer;
                ITopologyRule          topologyRule          = new TopologyRuleClass();
                topologyRule.TopologyRuleType = esriTopologyRuleType.esriTRTLineNoOverlap;
                topologyRule.OriginClassID    = featureClass.ObjectClassID;
                topologyRule.Name             = "Roads No Overlap";

                if (topologyRuleContainer.get_CanAddRule(topologyRule))
                {
                    topologyRuleContainer.AddRule(topologyRule);
                }

                topologyRule = new TopologyRuleClass();
                topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTLineNoDangles;
                topologyRule.OriginClassID     = featureClass.ObjectClassID;
                topologyRule.AllOriginSubtypes = true;
                topologyRule.Name = "Roads No Dangles";

                // Add the rule to the Topology
                if (topologyRuleContainer.get_CanAddRule(topologyRule))
                {
                    topologyRuleContainer.AddRule(topologyRule);
                }
            }
        }
        private void AddRuleToTopology(ITopology topology, esriTopologyRuleType ruleType, string ruleName, IFeatureClass featureClass)
        {
            ITopologyRule topologyRule = new TopologyRuleClass();

            topologyRule.TopologyRuleType  = ruleType;
            topologyRule.Name              = ruleName;
            topologyRule.OriginClassID     = featureClass.FeatureClassID;
            topologyRule.AllOriginSubtypes = true;
            ITopologyRuleContainer topologyRuleConatiner = topology as ITopologyRuleContainer;

            if (topologyRuleConatiner.get_CanAddRule(topologyRule))
            {
                topologyRuleConatiner.AddRule(topologyRule);
            }
            else
            {
                throw new ArgumentException("Counld not add specified rule to the topology");
            }
        }
        /// <summary>
        /// 重复线
        /// </summary>
        private void Line_redo(object para)
        {
            Plugin.Application.IAppFormRef pAppForm  = para as Plugin.Application.IAppFormRef;
            System.Data.DataTable          Datatable = new System.Data.DataTable(); //手动建立一个数据表,将得到的数据邦定到检查结果当中显示
            Datatable.Columns.Add("重复线", typeof(string));                           //创建一列
            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();

            ClearGrid.Operate(pAppForm, _AppHk);
            #region 打开要操作的数据集
            if (_AppHk.MapControl.LayerCount == 0)
            {
                return;                                   //如果MAP上打开的图层为空,就返回
            }
            SetCheckState.CheckShowTips(pAppForm, "重复线检查开始,准备载入检查数据,请稍后.....");
            int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            IGeoDataset            pGeoDataset = SetCheckState.Geodatabase;
            ITopologyRuleContainer pRuleCont   = SetCheckState.pT as ITopologyRuleContainer;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象
            #endregion
            try
            {
                #region 遍历整个数据集要素
                ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查
                for (int l = 0; l < L_count; l++)
                {
                    ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层
                    #region                                          //判别是不是组,如果是,就从组中取一个层
                    if (layer_1 is IGroupLayer && layer_1.Name == SetCheckState.CheckDataBaseName)
                    {
                        ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层
                        int             group_count  = grouplayer_1.Count;
                        if (group_count == 0)
                        {
                            return;
                        }
                        for (int g = 0; g < group_count; g++)
                        {
                            ILayer        layer_temp    = grouplayer_1.get_Layer(g);
                            IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass;
                            #region 将符合线要素的类加入到拓扑中
                            if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                        break;
                    }
                    #endregion
                }
                #endregion
                SetCheckState.CheckShowTips(pAppForm, "数据准备完毕,准备进度显示数据,请稍后.....");
                #region 通过过滤后的要素类来进行拓扑检查
                int Count = list_line.Count;//总要遍历的层数
                if (Count == 0)
                {
                    _AppHk.CurrentThread = null;
                    SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!");
                    SetCheckState.Message(pAppForm, "提示", "线重复检查完成!");
                    //选中检查出错列表
                    ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树
                SetCheckState.CheckShowTips(pAppForm, "进度数据准备完毕,马上进入拓扑分析,请稍后.....");
                for (int N = 0; N < Count; N++)
                {
                    IFeatureClass TempClass = list_line[N] as IFeatureClass;                    //将对象转成相应的要素类
                    IDataset      ds        = TempClass as IDataset;
                    SetCheckState.TreeCheckFun(ds.Name, N, _AppHk);                             //调用树节点选中
                    ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                    topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTLineNoOverlap; //使用规则的类型(线不重叠)
                    topologyRule.Name              = "www";                                     //给规则取个名
                    topologyRule.OriginClassID     = TempClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes = true;
                    pRuleCont.AddRule(topologyRule);
                    ISegmentCollection pLocation = new PolygonClass();                            //使用多边形接口 实例一个面的片段
                    pLocation.SetRectangle(pGeoDataset.Extent);                                   //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
                    IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
                    IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //返回利用拓扑规则验证后的出错结果

                    SetCheckState.CheckShowTips(pAppForm, "拓扑分析中,请稍后.....");
                    IErrorFeatureContainer    pErrFeatCon      = SetCheckState.pT as IErrorFeatureContainer;                                                                 //实例一个拓扑出错的容器
                    IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举
                    int num = N + 1;                                                                                                                                         //由于层的索引是从0开始的,所以得加1

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();                                                                                            //开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    //将当前层的所有出错要素放入动态数组当中
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    SetCheckState.CheckShowTips(pAppForm, "拓扑分析完毕,进行具体检查操作,请稍后.....");
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "无重复线准备进行下一个图层操作,请稍后....");
                        continue;
                    }
                    SetCheckState.CheckShowTips(pAppForm, "正在进行" + TempClass.AliasName + "图层操作,请稍后....");
                    pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示
                    #region 遍历出错
                    for (int p = 0; p < P_count; p++)
                    {
                        int i = p + 1;                                                                                            //方便计算
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值
                        ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature;
                        int OriginOID = pTopoErrFeat.OriginOID;                                                                   //源ID

                        int      DestinationOID = pTopoErrFeat.DestinationOID;                                                    //目标ID
                        IFeature source_fe      = TempClass.GetFeature(OriginOID);                                                //源要素
                        IFeature des_fe         = TempClass.GetFeature(DestinationOID);                                           //目标要素

                        ///求几何空间差值,必须要两种情况考虑:a->b  b->a,如果同时都为空,说明两个重复
                        ITopologicalOperator Origin_0     = des_fe.Shape as ITopologicalOperator;              //空间几何运算
                        IGeometry            difference_0 = Origin_0.Difference(source_fe.Shape as IGeometry); //求两个面的差值

                        ITopologicalOperator Origin     = source_fe.Shape as ITopologicalOperator;             //空间几何运算
                        IGeometry            difference = Origin.Difference(des_fe.Shape as IGeometry);        //求两个面的差值

                        if (difference.IsEmpty && difference_0.IsEmpty)
                        {
                            StringBuilder origin_temp      = new StringBuilder(); //除了SHAPE外的字段对比源
                            StringBuilder destination_temp = new StringBuilder(); //除了SHAPE外的字段对比目标

                            ArrayList list  = Foreach();                          //得到我们需要遍历的对比字段
                            int       count = list.Count;
                            if (count > 0)
                            {
                                for (int n = 0; n < count; n++)
                                {
                                    int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString());       //查看我们要对比的字段名是不是存在 源

                                    int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString()); //查看我们要对比的字段名是不是存在 目标
                                    if (index >= 0 && index1 >= 0)
                                    {
                                        origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index));
                                        destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1));
                                    }
                                }
                                if (origin_temp.Equals(destination_temp) && origin_temp != null && destination_temp != null)
                                {
                                    string temp             = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();
                                    System.Data.DataRow Row = Datatable.NewRow();
                                    Row[0] = temp;
                                    Datatable.Rows.Add(Row);
                                    SetCheckState.CheckShowTips(pAppForm, temp);
                                }
                                else
                                {
                                    pTopoErrFeat = pEnumTopoErrFeat.Next();
                                    continue;
                                }
                            }
                            else
                            {
                                string temp             = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();
                                System.Data.DataRow Row = Datatable.NewRow();
                                Row[0] = temp;
                                Datatable.Rows.Add(Row);
                                SetCheckState.CheckShowTips(pAppForm, temp);
                            }
                        }
                    }
                    #endregion

                    pRuleCont.DeleteRule(topologyRule);//移除拓扑规则

                    if (num == Count)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "重复线检查马上完成,请稍后....");
                        break;
                    }
                }
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //显示完成隐藏进度条
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件进行方法的委托,因为得让它成为安全的
                _AppHk.CurrentThread = null;                                                                     //将线程置空
                SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!");
                SetCheckState.Message(pAppForm, "提示", "线重复检查完成!");
                //选中检查出错列表
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                #endregion
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;//将线程置空
                MessageBox.Show(ex.ToString());
                return;
            }
        }
Beispiel #12
0
        /// <summary>
        /// 面套面处理主函数
        /// </summary>
        /// <param name="_AppHk"></param>
        private void ExcutePolygonOverlapTreat()
        {
            Plugin.Application.IAppFormRef pAppFrm = _AppHk as Plugin.Application.IAppFormRef;

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在获取所有面层..." });
            //获取所有面层
            List <ILayer> listLayers = GetCheckLayers(_AppHk.MapControl.Map, "更新修编数据");

            if (listLayers == null)
            {
                return;
            }
            List <ILayer> listCheckLays = new List <ILayer>();

            //遍历更新库体里的所有层
            foreach (ILayer pTempLay in listLayers)
            {
                IFeatureLayer pFeatLay = pTempLay as IFeatureLayer;
                if (pFeatLay == null)
                {
                    continue;
                }
                if (pFeatLay.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    continue;
                }
                //接边针对的是线和面,所以我们操作时只需对线和面层进行即可
                if (pFeatLay.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon)
                {
                    continue;
                }

                listCheckLays.Add(pTempLay);
            }
            if (listCheckLays.Count == 0)
            {
                return;
            }

            //遍历各个面层并与其它面层建立拓扑规则以获取所有存在重叠的最小面
            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在建立拓扑规则..." });
            Dictionary <ITopologyRule, IFeatureClass> dicTemp = new Dictionary <ITopologyRule, IFeatureClass>();
            ITopologyRuleContainer pTopologyRuleContainer     = SetCheckState.pT as ITopologyRuleContainer;//使用建立好的拓扑

            //遍历我们得出的所有面层并操作
            foreach (ILayer pLay in listCheckLays)
            {
                IFeatureLayer pFeatLay = pLay as IFeatureLayer;
                if (pFeatLay == null)
                {
                    continue;
                }
                ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTAreaNoOverlap; //使用规则的类型(面不相交)
                topologyRule.OriginClassID     = pFeatLay.FeatureClass.FeatureClassID;
                topologyRule.AllOriginSubtypes = true;
                topologyRule.Name = pFeatLay.FeatureClass.AliasName;
                if (pTopologyRuleContainer.get_CanAddRule(topologyRule) == true)//提示拓扑规则是否可以被添加
                {
                    pTopologyRuleContainer.AddRule(topologyRule);
                    dicTemp.Add(topologyRule, pFeatLay.FeatureClass);
                }

                foreach (ILayer pOtherLay in listCheckLays)
                {
                    if (pOtherLay == pLay)
                    {
                        continue;
                    }
                    IFeatureLayer pOtherFeatLay = pOtherLay as IFeatureLayer;
                    if (pOtherFeatLay == null)
                    {
                        continue;
                    }
                    topologyRule = new TopologyRuleClass();
                    topologyRule.TopologyRuleType       = esriTopologyRuleType.esriTRTAreaNoOverlapArea;
                    topologyRule.OriginClassID          = pFeatLay.FeatureClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes      = true;
                    topologyRule.DestinationClassID     = pOtherFeatLay.FeatureClass.FeatureClassID;
                    topologyRule.AllDestinationSubtypes = true;
                    topologyRule.Name = pFeatLay.FeatureClass.AliasName + " AreaNoOverlapArea with " + pOtherFeatLay.FeatureClass.AliasName;
                    if (pTopologyRuleContainer.get_CanAddRule(topologyRule) == true)
                    {
                        pTopologyRuleContainer.AddRule(topologyRule);
                        dicTemp.Add(topologyRule, pFeatLay.FeatureClass);
                    }
                }
            }

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在验证拓扑..." });
            ISegmentCollection pLocation = new PolygonClass();                            //使用多边形接口

            pLocation.SetRectangle(SetCheckState.Geodatabase.Extent);                     //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
            IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
            IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //验证拓扑

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在分析获取要处理的要素..." });
            pAppFrm.MainForm.Invoke(new ShowProgress(ShowProgressBar), new object[] { pAppFrm, true });
            pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, 0, dicTemp.Count, 0 });
            //获取所有存在重叠的最小面
            Dictionary <IFeature, IFeatureClass> dicCheckFeats = new Dictionary <IFeature, IFeatureClass>();
            IErrorFeatureContainer pErrFeatCon = SetCheckState.pT as IErrorFeatureContainer;
            IEnumRule pEnumRule = pTopologyRuleContainer.Rules;

            pEnumRule.Reset();
            ITopologyRule pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            int           intcnt            = 0;

            while (pTempTopologyRule != null)
            {
                intcnt++;
                pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, -1, -1, intcnt });
                if (!(pTempTopologyRule.TopologyRuleType == esriTopologyRuleType.esriTRTAreaNoOverlap || pTempTopologyRule.TopologyRuleType == esriTopologyRuleType.esriTRTAreaNoOverlapArea))
                {
                    continue;
                }
                IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(SetCheckState.Geodatabase.SpatialReference, pTempTopologyRule, SetCheckState.Geodatabase.Extent, true, false);
                ITopologyErrorFeature     pTopoErrFeat     = pEnumTopoErrFeat.Next();

                IFeatureClass pOrgFeatCls = null;
                if (dicTemp.ContainsKey(pTempTopologyRule))
                {
                    pOrgFeatCls = dicTemp[pTempTopologyRule];
                }
                if (pOrgFeatCls == null)
                {
                    break;
                }
                IDataset pDatasetTemp = pOrgFeatCls as IDataset;
                while (pTopoErrFeat != null)
                {
                    IFeature orgFeat  = pOrgFeatCls.GetFeature(pTopoErrFeat.OriginOID);
                    bool     bHasFeat = false;
                    foreach (ILayer pLay in listCheckLays)
                    {
                        IFeatureLayer pFeatLay = pLay as IFeatureLayer;
                        if (pFeatLay == null)
                        {
                            continue;
                        }
                        IDataset pDataset = pFeatLay.FeatureClass as IDataset;
                        string   strCon   = "";
                        //排除指定要素
                        if (pDataset.Name == pDatasetTemp.Name)
                        {
                            strCon = "OBJECTID<>" + orgFeat.OID.ToString();
                        }

                        //判断面orgFeat内是否包含有面
                        if (HasFeatureWithInGeometry(pFeatLay.FeatureClass, orgFeat.Shape, strCon) == true)
                        {
                            bHasFeat = true;
                            break;
                        }
                    }

                    if (bHasFeat == false)
                    {
                        dicCheckFeats.Add(orgFeat, pOrgFeatCls);
                    }
                    pTopoErrFeat = pEnumTopoErrFeat.Next();
                }

                pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            }

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "处理数据中..." });
            pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, 0, dicCheckFeats.Count, 0 });

            Exception err = null;
            //开启编辑  wjj 20090921
            IDataset       pFeatDataset   = SetCheckState.Geodatabase as IDataset;
            IWorkspaceEdit pWorkspaceEdit = pFeatDataset.Workspace as IWorkspaceEdit;

            if (pWorkspaceEdit.IsBeingEdited() == false)
            {
                pWorkspaceEdit.StartEditing(false);
            }

            //遍历上步所获得到的重叠最小面,分析获取包含该面的所有面并根据面积排序
            intcnt = 0;
            foreach (KeyValuePair <IFeature, IFeatureClass> keyvlue in dicCheckFeats)
            {
                intcnt++;
                pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, -1, -1, intcnt });
                IFeature pFeat = keyvlue.Key;
                Dictionary <IFeature, IFeatureClass> dicFeats = GetFeaturesByGeometry(pFeat, listCheckLays);
                bool bDel = false;
                if (dicFeats.Count > 0)
                {
                    //从外到内做处理,处理原则分类代码相同则利用小面套空大面并删除小面,不同则小面套空大面
                    IFeature[] pFeatArray = new IFeature[dicFeats.Count];
                    dicFeats.Keys.CopyTo(pFeatArray, 0);
                    for (int i = 0; i < dicFeats.Count - 1; i++)
                    {
                        if (bDel == false)
                        {
                            IFeature pBigFeat = pFeatArray[i];
                            IFeature pLowFeat = pFeatArray[i + 1];

                            //小面掏空大面
                            UpdateFeatureByOverlapArea(dicFeats[pBigFeat], "OBJECTID=" + pBigFeat.OID.ToString(), pLowFeat.Shape, out err);
                            if (pBigFeat.get_Value(pBigFeat.Fields.FindField("CODE")).ToString() == pLowFeat.get_Value(pLowFeat.Fields.FindField("CODE")).ToString())
                            {
                                SysCommon.Gis.ModGisPub.DelFeature(dicFeats[pLowFeat], "OBJECTID=" + pLowFeat.OID.ToString(), out err);
                                bDel = true;
                            }
                            else
                            {
                                bDel = false;
                            }
                        }
                        else
                        {
                            bDel = false;
                        }
                    }


                    IFeature pLastFeat = pFeatArray[dicFeats.Count - 1];
                    //小面掏空大面
                    UpdateFeatureByOverlapArea(dicFeats[pLastFeat], "OBJECTID=" + pLastFeat.OID.ToString(), pFeat.Shape, out err);
                    if (pLastFeat.get_Value(pLastFeat.Fields.FindField("CODE")).ToString() == pFeat.get_Value(pFeat.Fields.FindField("CODE")).ToString())
                    {
                        SysCommon.Gis.ModGisPub.DelFeature(dicCheckFeats[pFeat], "OBJECTID=" + pFeat.OID.ToString(), out err);
                        bDel = true;
                    }
                    else
                    {
                        bDel = false;
                    }
                }
            }

            pEnumRule.Reset();
            pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            while (pTempTopologyRule != null)
            {
                pTopologyRuleContainer.DeleteRule(pTempTopologyRule);
                pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            }

            //结束编辑 wjj 20090921
            if (pWorkspaceEdit.IsBeingEdited() == true)
            {
                pWorkspaceEdit.StopEditing(true);
            }

            _AppHk.CurrentThread = null;
            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "" });
            pAppFrm.MainForm.Invoke(new ShowProgress(ShowProgressBar), new object[] { pAppFrm, false });
            pAppFrm.MainForm.Invoke(new ShowForm(ShowErrForm), new object[] { "提示", "处理完毕!" });
        }
        /// <summary>
        /// 重复面
        /// </summary>
        private void Cover(object para)
        {
            Plugin.Application.IAppFormRef pAppForm  = para as Plugin.Application.IAppFormRef;
            System.Data.DataTable          Datatable = new System.Data.DataTable();//手动建立一个数据表,将得到的数据邦定到检查结果当中显示

            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();

            ClearGrid.Operate(pAppForm, _AppHk);
            Datatable.Columns.Add("重复面", typeof(string));//创建一列

            #region 打开要操作的数据集

            int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            SetCheckState.CheckShowTips(pAppForm, "面重复检查开始......");
            IGeoDataset            pGeoDataset = SetCheckState.Geodatabase;
            ITopologyRuleContainer pRuleCont   = SetCheckState.pRuleCont;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象
            #endregion
            try
            {
                #region 遍历整个数据集要素
                ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查
                for (int l = 0; l < L_count; l++)
                {
                    ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层
                    #region                                          //判别是不是组,如果是,就从组中取一个层
                    if (layer_1 is IGroupLayer && layer_1.Name == SetCheckState.CheckDataBaseName)
                    {
                        ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层
                        int             group_count  = grouplayer_1.Count;
                        if (group_count == 0)
                        {
                            return;
                        }
                        for (int g = 0; g < group_count; g++)
                        {
                            ILayer        layer_temp    = grouplayer_1.get_Layer(g);
                            IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass;
                            #region 将符合线要素的类加入到拓扑中
                            if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                #endregion
                int Count = list_line.Count;
                if (Count == 0)
                {
                    SetCheckState.CheckShowTips(pAppForm, "重复面检查完成!");
                    _AppHk.CurrentThread = null;
                    SetCheckState.Message(pAppForm, "提示", "面重复检查完成!");
                    //选中检查出错列表
                    ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                    return;
                }
                if (Count == 0)
                {
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树图
                SetCheckState.CheckShowTips(pAppForm, "检查数据准备完毕,请稍后........");
                #region 通过过滤后的要素类来进行拓扑检查
                for (int N = 0; N < Count; N++)
                {
                    int num = N + 1;//由于层的索引是从0开始的,所以得加1

                    #region 创建拓扑并验证拓扑
                    IFeatureClass TempClass = list_line[N] as IFeatureClass;                    //将对象转成相应的要素类
                    IDataset      ds        = TempClass as IDataset;
                    SetCheckState.TreeCheckFun(ds.Name, N, _AppHk);                             //调用树节点选中方法
                    ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                    topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTAreaNoOverlap; //使用规则的类型(面不相交)
                    topologyRule.Name              = "www";                                     //给规则取个名
                    topologyRule.OriginClassID     = TempClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes = true;
                    pRuleCont.AddRule(topologyRule);


                    ISegmentCollection pLocation = new PolygonClass();                            //使用多边形接口
                    pLocation.SetRectangle(pGeoDataset.Extent);                                   //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
                    IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
                    IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //验证拓扑

                    SetCheckState.CheckShowTips(pAppForm, "正在进行拓扑分析,请稍后........");
                    IErrorFeatureContainer    pErrFeatCon      = SetCheckState.pT as IErrorFeatureContainer;                                                                 //实例一个拓扑出错的容器
                    IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举
                    #endregion

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();//开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    //将当前层的所有出错要素放入动态数组当中
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "图层完好,准备进行下一个图层,请稍后........");
                        continue;
                    }
                    pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示
                    #region 遍历出错
                    for (int p = 0; p < P_count; p++)
                    {
                        int i = p + 1;                                                                                            //方便计算
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值
                        ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature;
                        int      OriginOID      = pTopoErrFeat.OriginOID;                                                         //源ID
                        int      DestinationOID = pTopoErrFeat.DestinationOID;                                                    //目标ID
                        IFeature source_fe      = TempClass.GetFeature(OriginOID);                                                //源要素
                        IFeature des_fe         = TempClass.GetFeature(DestinationOID);                                           //目标要素
                        #region 通过拓扑出来的错进行再次分析求重复面
                        ///求几何空间差值,必须要两种情况考虑:a->b  b->a,如果同时都为空,说明两个重复
                        ITopologicalOperator Origin_0     = des_fe.Shape as ITopologicalOperator;              //空间几何运算
                        IGeometry            difference_0 = Origin_0.Difference(source_fe.Shape as IGeometry); //求两个面的差值

                        ITopologicalOperator Origin     = source_fe.Shape as ITopologicalOperator;             //空间几何运算
                        IGeometry            difference = Origin.Difference(des_fe.Shape as IGeometry);        //求两个面的差值


                        if (difference.IsEmpty && difference_0.IsEmpty)
                        {
                            #region MyRegion
                            //    StringBuilder origin_temp = new StringBuilder();//除了SHAPE外的字段对比源
                            //    StringBuilder destination_temp = new StringBuilder();//除了SHAPE外的字段对比目标
                            //    //IDataset ds = TempClass as IDataset;
                            //    ArrayList list = Foreach();//调用要对比的XML文件里的字段名
                            //    int count = list.Count;
                            //    #region 通过拓扑出错及对出错的对象再次的进行差值及字段对比,得出最终的结果是否一样
                            //    if (count > 0)
                            //    {
                            //        #region 得到要实际比较的字段值
                            //        for (int n = 0; n < count; n++)
                            //        {
                            //            int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString());//得到源的列ID

                            //            int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString());//得到目标的列ID
                            //            if (index > 0 && index1 > 0)
                            //            {
                            //                origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index));//在对应的要素类当中取出源对应ID列的值,加入BUILDER中
                            //                destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1));//在对应的要素类当中取出目标对应的ID列值,加入目录的BUILDER中
                            //            }
                            //        }
                            //        #endregion
                            //        #region 比较两个值是否一样
                            //        if (origin_temp.ToString() == destination_temp.ToString() && origin_temp != null && destination_temp != null)//将两个列的值进行对比
                            //        {
                            #endregion
                            string temp             = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();
                            System.Data.DataRow Row = Datatable.NewRow(); //新创建一个行
                            Row[0] = temp;
                            Datatable.Rows.Add(Row);                      //将行加入到表数据集中
                            SetCheckState.CheckShowTips(pAppForm, temp);
                            #region
                            //        }
                            //        else
                            //        {
                            //            pTopoErrFeat = pEnumTopoErrFeat.Next();//遍历下一个错误
                            //            continue;
                            //        }
                            //        #endregion
                            //    }
                            //    else
                            //    {
                            //        string temp = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();//将结果组织起来,放到一个字符串当中
                            //        System.Data.DataRow Row = Datatable.NewRow();//新创建一个行
                            //        Row[0] = temp;
                            //        Datatable.Rows.Add(Row);//将行加入到表数据集中
                            //    }
                            #endregion
                        }
                        #endregion
                    }

                    pRuleCont.DeleteRule(topologyRule);
                    #endregion
                    if (num == Count)
                    {
                        string Case = "马上完成请稍后.....";//状态栏显示
                        SetCheckState.CheckShowTips(pAppForm, Case);
                    }
                }
                #endregion
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件使用委托
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //是否显示进度条,加载让它显示
                _AppHk.CurrentThread = null;
                SetCheckState.Message(pAppForm, "提示", "面重复检查完成!");
                //选中检查出错列表
                SetCheckState.CheckShowTips(pAppForm, "面重复检查完成!");
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;
                SetCheckState.Message(pAppForm, "错误", ex.ToString());
                return;
            }
        }
Beispiel #14
0
        /// <summary>
        /// 悬挂点
        /// </summary>
        private void Point_dangles(object par)
        {
            Plugin.Application.IAppFormRef pAppForm  = par as Plugin.Application.IAppFormRef;
            System.Data.DataTable          Datatable = new System.Data.DataTable(); //手动建立一个数据表,将得到的数据邦定到检查结果当中显示
            Datatable.Columns.Add("悬挂点重复", typeof(string));                         //创建一列
            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();

            ClearGrid.Operate(pAppForm, _AppHk);
            #region 打开要操作的数据集
            if (_AppHk.MapControl.LayerCount == 0)
            {
                return;                                   //如果MAP上打开的图层为空,就返回
            }
            SetCheckState.CheckShowTips(pAppForm, "悬挂点重复检查开始.....");
            int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            IGeoDataset            pGeoDataset = SetCheckState.Geodatabase;
            ITopologyRuleContainer pRuleCont   = SetCheckState.pT as ITopologyRuleContainer;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象

            #endregion
            try
            {
                #region 遍历整个数据集要素
                ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查
                for (int l = 0; l < L_count; l++)
                {
                    ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层
                    #region                                          //判别是不是组,如果是,就从组中取一个层
                    if (layer_1 is IGroupLayer)
                    {
                        ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层
                        int             group_count  = grouplayer_1.Count;
                        if (group_count == 0)
                        {
                            return;
                        }
                        for (int g = 0; g < group_count; g++)
                        {
                            ILayer        layer_temp    = grouplayer_1.get_Layer(g);
                            IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass;
                            #region 将符合线要素的类加入到拓扑中
                            if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                #endregion
                int Count = list_line.Count;//得到拓扑层的总数
                if (Count == 0)
                {
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//实始化树图
                #region 通过过滤后的要素类来进行拓扑检查
                for (int N = 0; N < Count; N++)
                {
                    int           num       = N + 1;                                            //由于层的索引是从0开始的,所以得加1
                    IFeatureClass TempClass = list_line[N] as IFeatureClass;                    //将对象转成相应的要素类
                    IDataset      ds        = TempClass as IDataset;
                    SetCheckState.TreeCheckFun(ds.Name, N, _AppHk);                             //调用节点选中方法
                    ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                    topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTLineNoDangles; //使用规则的类型(悬挂点)
                    topologyRule.Name              = "www";                                     //给规则取个名
                    topologyRule.OriginClassID     = TempClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes = true;
                    pRuleCont.AddRule(topologyRule);


                    ISegmentCollection pLocation = new PolygonClass(); //使用多边形接口
                    pLocation.SetRectangle(pGeoDataset.Extent);        //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
                    IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
                    IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope);

                    IErrorFeatureContainer    pErrFeatCon      = SetCheckState.pT as IErrorFeatureContainer;                                                                 //实例一个拓扑出错的容器
                    IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();                                                                                            //开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    #region 遍历出错
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm });//是否显示进度条,加载让它显示
                        SetCheckState.CheckShowTips(pAppForm, "图层完好,无悬挂点!");
                        continue;
                    }
                    pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示
                    #region 遍历错误
                    for (int p = 0; p < P_count; p++)
                    {
                        int i = p + 1;                                                                                            //方便计算
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值
                        ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature;
                        int OriginOID = pTopoErrFeat.OriginOID;                                                                   //源ID
                        if (i % 2 != 0)
                        {
                            string temp             = ds.Name + " 悬挂ID:" + OriginOID.ToString();
                            System.Data.DataRow Row = Datatable.NewRow(); //新创建一个行
                            Row[0] = temp;
                            Datatable.Rows.Add(Row);                      //将行加入到表数据集中
                            SetCheckState.CheckShowTips(pAppForm, temp);
                        }
                    }
                    #endregion

                    pRuleCont.DeleteRule(topologyRule);//删除拓扑规则
                    if (num == Count)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "马上完成,请稍后....");
                    }
                    #endregion
                }
                #endregion
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件使用委托
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //是否显示进度条,加载让不显示
                SetCheckState.CheckShowTips(pAppForm, "悬挂点检查完成!");
                _AppHk.CurrentThread = null;
                SetCheckState.Message(pAppForm, "提示", "悬挂点检查完成!");
                //选中检查出错列表
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;
                MessageBox.Show(ex.ToString());
                return;
            }
        }
Beispiel #15
0
 private void btnNext_Click(object sender, EventArgs e)
 {
     if (this.int_1 != 4)
     {
         this.int_1++;
         this.method_0();
     }
     else
     {
         ITopology          topology;
         Exception          exception2;
         ITopologyContainer pFeatDataset = (ITopologyContainer)this.m_pFeatDataset;
         try
         {
             topology = pFeatDataset.CreateTopology(this.txtTopologyName.Text,
                                                    double.Parse(this.txtLimiteValue.Text), -1, "");
         }
         catch (COMException exception)
         {
             if (exception.ErrorCode == -2147220969)
             {
                 MessageBox.Show("非数据所有者,无法创建拓扑!");
             }
             else
             {
                 MessageBox.Show(exception.Message);
             }
             return;
         }
         catch (Exception exception4)
         {
             exception2 = exception4;
             MessageBox.Show(exception2.Message);
             return;
         }
         int count = this.iarray_1.Count;
         int index = 0;
         while (true)
         {
             if (index >= count)
             {
                 break;
             }
             int tag = (int)this.listViewPri.Items[index].Tag;
             try
             {
                 topology.AddClass((IClass)this.iarray_1.get_Element(index), 5.0, tag, 1, false);
             }
             catch (COMException exception3)
             {
                 if (exception3.ErrorCode != -2147215019)
                 {
                 }
                 Logger.Current.Error("", exception3, "");
             }
             catch (Exception exception6)
             {
                 exception2 = exception6;
                 Logger.Current.Error("", exception2, "");
             }
             index++;
         }
         ITopologyRuleContainer container2 = (ITopologyRuleContainer)topology;
         index = 0;
         while (true)
         {
             if (index >= this.listRule.Items.Count)
             {
                 break;
             }
             try
             {
                 container2.AddRule((ITopologyRule)this.listRule.Items[index].Tag);
             }
             catch (Exception exception7)
             {
                 exception2 = exception7;
                 Logger.Current.Error("", exception2, "");
             }
             index++;
         }
         base.DialogResult = DialogResult.OK;
         base.Close();
     }
 }