private void method_0(IGeometricNetwork igeometricNetwork_1) { try { IFeatureClassContainer featureDataset = (IFeatureClassContainer)igeometricNetwork_1.FeatureDataset; IEnumRule rules = igeometricNetwork_1.Rules; rules.Reset(); for (IRule rule2 = rules.Next(); rule2 != null; rule2 = rules.Next()) { if (rule2 is IConnectivityRule) { IConnectivityRule rule3 = (IConnectivityRule)rule2; if (rule3.Category == -1) { IJunctionConnectivityRule2 rule4 = (IJunctionConnectivityRule2)rule3; featureDataset.get_ClassByID(rule4.EdgeClassID); featureDataset.get_ClassByID(rule4.JunctionClassID); } else if (rule3.Type == esriRuleType.esriRTEdgeConnectivity) { IEdgeConnectivityRule rule5 = (IEdgeConnectivityRule)rule3; featureDataset.get_ClassByID(rule5.FromEdgeClassID); featureDataset.get_ClassByID(rule5.ToEdgeClassID); featureDataset.get_ClassByID(rule5.DefaultJunctionClassID); for (int i = 0; i < rule5.JunctionCount; i++) { } } } } } catch { } }
private void method_1() { try { this.listView1.Items.Clear(); string[] items = new string[3]; ITopologyRuleContainer container = this.itopology_0 as ITopologyRuleContainer; IEnumRule rules = container.Rules; rules.Reset(); for (IRule rule2 = rules.Next(); rule2 != null; rule2 = rules.Next()) { items[0] = (this.itopology_0 as IFeatureClassContainer).get_ClassByID( (rule2 as ITopologyRule).OriginClassID).AliasName; items[1] = this.method_0((rule2 as ITopologyRule).TopologyRuleType); if (((rule2 as ITopologyRule).OriginClassID != (rule2 as ITopologyRule).DestinationClassID) && ((rule2 as ITopologyRule).DestinationClassID != 0)) { items[2] = (this.itopology_0 as IFeatureClassContainer).get_ClassByID( (rule2 as ITopologyRule).DestinationClassID).AliasName; } ListViewItem item = new ListViewItem(items) { Tag = new Class2(rule2 as ITopologyRule, false) }; this.listView1.Items.Add(item); } } catch (Exception exception) { Logger.Current.Error("", exception, ""); } }
private void method_3(int int_0) { IEnumRule rule = (this.itopology_0 as ITopologyRuleContainer).get_RulesByClass(int_0); for (IRule rule2 = rule.Next(); rule2 != null; rule2 = rule.Next()) { int index = this.listView1.Items.Count - 1; while (index >= 0) { ListViewItem item = this.listView1.Items[index]; Class2 tag = item.Tag as Class2; if (tag.TopoRule == rule2) { goto Label_0071; } index--; } continue; Label_0071: this.listView1.Items.RemoveAt(index); } }
private IList method_4(ITopology itopology_0) { IList list = new ArrayList(); ITopologyRuleContainer container = itopology_0 as ITopologyRuleContainer; IEnumRule rules = container.Rules; rules.Reset(); for (ITopologyRule rule2 = rules.Next() as ITopologyRule; rule2 != null; rule2 = rules.Next() as ITopologyRule) { bool flag; bool flag2; bool flag3; rule2.ErrorShapeTypes(out flag, out flag2, out flag3); if (flag3) { list.Add(rule2); } } return(list); }
/// <summary> /// 获取拓扑的全部拓扑规则 /// </summary> /// <param name="topology"></param> /// <returns></returns> public static List <ITopologyRule> GetTopologyRules(this ITopology topology) { List <ITopologyRule> result = new List <ITopologyRule>(); ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology; IEnumRule enumRule = topologyRuleContainer.Rules; enumRule.Reset(); IRule rule; while ((rule = enumRule.Next()) != null) { result.Add((ITopologyRule)rule); } return(result); }
/// <summary> /// 获取指定的拓扑规则类型 /// </summary> /// <param name="topology"></param> /// <param name="topoRuleName">拓扑规则名称或esriTopologyRuleType.ToString()的结果(eg:)</param> /// <returns></returns> public static ITopologyRule GetTopoRuleTypeByName(this ITopology topology, string topoRuleName) { ITopologyRuleContainer topologyRuleContainer = (ITopologyRuleContainer)topology; IEnumRule enumRule = topologyRuleContainer.Rules; enumRule.Reset(); IRule rule; while ((rule = enumRule.Next()) != null) { var topoRule = rule as ITopologyRule; if (topoRule.Name == topoRuleName || topoRule.TopologyRuleType.ToString() == topoRuleName) { return(topoRule); } } return(null); }
/// <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[] { "提示", "处理完毕!" }); }
private static IEnumerable <ConstraintNode> GetAttributeRuleNodes( [NotNull] ITable table, [NotNull] ISubtypes subtypes, bool allowNullForCodedValueDomains, bool allowNullForRangeDomains) { Assert.ArgumentNotNull(table, nameof(table)); Assert.ArgumentNotNull(subtypes, nameof(subtypes)); var rootNodes = new List <ConstraintNode>(); string subtypeField = subtypes.SubtypeFieldName; if (!string.IsNullOrEmpty(subtypeField)) { rootNodes.Add(CreateValidSubtypesConstraint(subtypes, subtypeField)); } var subtypeNodes = new Dictionary <int, ConstraintNode>(); var workspaceDomains = DatasetUtils.GetWorkspace(table) as IWorkspaceDomains; DomainConstraints domainConstraints = workspaceDomains != null ? new DomainConstraints(workspaceDomains, allowNullForCodedValueDomains, allowNullForRangeDomains) : null; IEnumRule rules = ((IValidation)table).Rules; rules.Reset(); IRule rule; while ((rule = rules.Next()) != null) { if (rule.Type != esriRuleType.esriRTAttribute) { continue; } var attributeRule = (IAttributeRule)rule; int subtype = attributeRule.SubtypeCode; IField field = TryGetField(table, attributeRule); if (field == null) { continue; } ConstraintNode subtypeParentNode = null; if (!string.IsNullOrEmpty(subtypeField)) { if (!subtypeNodes.TryGetValue(subtype, out subtypeParentNode)) { subtypeParentNode = CreateSubtypeParentNode(subtype, subtypeField); subtypeNodes.Add(subtype, subtypeParentNode); rootNodes.Add(subtypeParentNode); } } DomainConstraint domainConstraint = domainConstraints?.GetConstraint(attributeRule); if (domainConstraint != null) { ConstraintNode domainNode = CreateDomainValueConstraint(field, domainConstraint); if (subtypeParentNode != null) { // add as child node to subtype selection node subtypeParentNode.Nodes.Add(domainNode); } else { // add as top-level node rootNodes.Add(domainNode); } } } return(rootNodes); }
/// <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; } }