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 #2
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 #3
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 #4
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); //输出错误
        }
Beispiel #5
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);//输出错误
        }
        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");
            }
        }
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);
            }
        }
        /// <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[] { "提示", "处理完毕!" });
        }