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(); } }
/// <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; } }
/// <summary> /// 面重叠检查错误列表 同层面检查 chenyafei 添加20101208 /// </summary> /// <param name="pFeaDatset">数据集</param> /// <param name="pTopo">拓扑</param> /// <param name="pTopoRuleType">拓扑规则</param> /// <param name="pOrgFeaClsNameDic">源图层名</param> /// <param name="pEnvelop">拓扑验证范围</param> /// <param name="pDataGrid">检查结果列表显示</param> /// <param name="outError"></param> public void GetAreaNoOverlopErrorList(IFeatureDataset pFeaDatset, ITopology pTopo, IEnvelope pEnvelop, DataGridViewX pDataGrid, out Exception outError) { outError = null; try { IFeatureClass oriFeaCls = null; //源要素类 IFeatureClass desFeaCls = null; //目标要素类 //依照拓扑规则获取错误要素 IErrorFeatureContainer pErrorFeaCon = pTopo as IErrorFeatureContainer; ITopologyRuleContainer pTopoRuleCon = pTopo as ITopologyRuleContainer; IEnumRule pEnumRule = pTopoRuleCon.Rules; pEnumRule.Reset(); ITopologyRule pTopoRule = pEnumRule.Next() as ITopologyRule; //遍历拓扑规则 while (pTopoRule != null) { //if (pTopoRule.TopologyRuleType != pTopoRuleType) //{ // pTopoRule = pEnumRule.Next() as ITopologyRule; // continue; //} IEnumTopologyErrorFeature pEnumErrorFea = null; try { pEnumErrorFea = pErrorFeaCon.get_ErrorFeatures( (pFeaDatset as IGeoDataset).SpatialReference, pTopoRule, pEnvelop, true, false); } catch (Exception ex) { ////********************************************* ////guozheng 2010-12-24 平安夜 added 系统异常日志 //if (ModData.SysLog == null) ModData.SysLog = new clsWriteSystemFunctionLog(); //ModData.SysLog.Write(ex); ////********************************************** RemoveTopo(pFeaDatset, pFeaDatset.Name, out outError); outError = ex; return; } if (pEnumErrorFea == null) { pTopoRule = pEnumRule.Next() as ITopologyRule; continue; } //进度条初始值 //ModData.m_ProgressBarDetail.Minimum = 0; //ModData.m_ProgressBarDetail.Value = 0; //ModData.m_ProgressBarDetail.Maximum = ModOperator.GetErrCount(pEnumErrorFea); int pValue = 0; //Application.DoEvents(); pEnumErrorFea = pErrorFeaCon.get_ErrorFeatures( (pFeaDatset as IGeoDataset).SpatialReference, pTopoRule, pEnvelop, true, false); ITopologyErrorFeature pErrorFea = pEnumErrorFea.Next(); //遍历错误要素,进行错误输出 while (pErrorFea != null) { double pMapx = 0; //错误定位点x double pMapy = 0; //错误定位点y string errFeaGeoStr = ""; //错误几何信息 string errCoorStr = ""; string pFeaClsName = ""; //要素类名称 int desID = pErrorFea.DestinationOID; //目标要素ID int oriID = pErrorFea.OriginOID; //源要素类ID IFeature oriFeature = null; //源要素 IFeature desFeature = null; //目标要素 int oriFeaClsID = pErrorFea.OriginClassID; //源要素类ID int desFeaClsID = pErrorFea.DestinationClassID; //目标要素类ID string errDes = ""; //错误描述 try { //若要素类为空,则说明是对数据集中的所有的同层面进行重叠检查 oriFeaCls = (pTopo as IFeatureClassContainer).get_ClassByID(oriFeaClsID); desFeaCls = oriFeaCls; } catch { } if (oriFeaCls != null && oriID > 0) { oriFeature = oriFeaCls.GetFeature(oriID); } else { //源要素OID oriID = -1; } if (desFeaCls != null && desID > 0) { desFeature = desFeaCls.GetFeature(desID); } else { //目标要素OID desID = -1; } double pMinArea = 0; //面积最小值 double pMaxArea = 0; //重叠面积最大值 pFeaClsName = (oriFeaCls as IDataset).Name; if (pFeaClsName.Contains(".")) { pFeaClsName = pFeaClsName.Substring(pFeaClsName.IndexOf('.') + 1); } //获得错误几何信息 GetZoomErrFea(pErrorFea as IFeature, out pMapx, out pMapy, out errFeaGeoStr, out errCoorStr); //目标数据库对应到元数据库中的OID int dicDesOID = -1; if (desFeature != null) { int index = desFeature.Fields.FindField(desFeaCls.OIDFieldName); if (index != -1) { if (desFeature.get_Value(index).ToString().Trim() != "") { dicDesOID = Convert.ToInt32(desFeature.get_Value(index).ToString().Trim()); } } } string errType = ""; if (pTopoRule.TopologyRuleType == esriTopologyRuleType.esriTRTAreaNoOverlap) { errDes = "OID为" + oriID + "的小班与OID为" + dicDesOID + "的小班之间有重叠"; errType = "面重叠检查"; } else if (pTopoRule.TopologyRuleType == esriTopologyRuleType.esriTRTAreaNoGaps) { errDes = "小班之间有缝隙"; errType = "面缝隙检查"; } //处理错误结果 ProcErrorList(errType, pFeaDatset, pFeaClsName, oriID, pFeaClsName, dicDesOID, pMapx, pMapy, errFeaGeoStr, pDataGrid, errDes, errCoorStr); //ProcErrorList(pFeaDatset, pFeaClsName, oriFeature, pFeaClsName, desID, pDataGrid, EnumCheckType.面重叠检查, pErrType, errDes); //错误数加1 //ModData.m_ErrCount++; //m_ErrCount++; //m_LabelRes.Text = "同层面重叠检查错误:" + m_ErrCount + "个"; //进度条 pValue++; //ModData.m_ProgressBarDetail.Value = pValue; //Application.DoEvents(); //实时处理windows消息 pErrorFea = pEnumErrorFea.Next(); } pTopoRule = pEnumRule.Next() as ITopologyRule; } } catch (Exception ex) { ////********************************************* ////guozheng 2010-12-24 平安夜 added 系统异常日志 //if (ModData.SysLog == null) ModData.SysLog = new clsWriteSystemFunctionLog(); //ModData.SysLog.Write(ex); ////********************************************** outError = ex; } }