Пример #1
0
 public ITopology Create_Topology(IFeatureWorkspace featureWorkspace, string featuredatasetName, string featureClassName, string topologyName)
 {
     try
     {
         //1.---打开拓朴所在的要素数据集,并创建拓朴
         IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(featuredatasetName);
         if (featureDataset != null)
         {
             ITopologyContainer topologyContainer = (ITopologyContainer)featureDataset;
             ITopology          topology          = topologyContainer.CreateTopology("topo", topologyContainer.DefaultClusterTolerance, -1, ""); //在这个地方报错
             //2.---给拓朴加入要素集
             IFeatureClassContainer featureclassContainer = (IFeatureClassContainer)featureDataset;
             IFeatureClass          featureClass          = featureclassContainer.get_ClassByName(featureClassName);
             topology.AddClass(featureClass, 5, 1, 1, false);  // Parameters: AddClass(IClass, double weight, int xyrank, int zrank, Boolean EventNotificationOnValidate).
             //3.---返回拓朴
             return(topology);
         }
     }
     catch (Exception ex)
     {
         //System.Diagnostics.Debug.WriteLine(ex.ToString());
         MessageBox.Show(ex.ToString());
     }
     return(null);
 }
Пример #2
0
        private void Progarm()
        {
            IWorkspace workspace = ArcClass.GetmdbWorkspace(mdbFilePath);

            if (workspace == null)
            {
                return;
            }
            IFeatureDataset featureDataset = ArcClass.GetFeatureDataset(workspace, "WJL");
            ISchemaLock     schemalock     = featureDataset as ISchemaLock;

            try
            {
                schemalock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                ITopologyContainer topologyContainer = featureDataset as ITopologyContainer;
                ITopology          topology          = topologyContainer.CreateTopology("ttt", topologyContainer.DefaultClusterTolerance, -1, "");
                IFeatureClass      featureClass      = ArcClass.GetFeatureClass(workspace, "PARK");

                AddRuleToTopology(topology, esriTopologyRuleType.esriTRTAreaNoOverlap, "NO Block OverLap", featureClass);

                IGeoDataset geoDataset = topology as IGeoDataset;
                IEnvelope   envelop    = geoDataset.Extent;
                ValidateTopology(topology, envelop);
            }catch (COMException comEx)
            {
            }
        }
Пример #3
0
        /// <summary>
        /// 在数据集中构建拓扑
        /// </summary>
        /// <param name="IN_TopoName">要生成拓扑的名称</param>
        /// <param name="IN_Tolerance">拓扑容差,可选,默认0.001</param>
        public void PUB_TopoBuild(string IN_TopoName, double IN_Tolerance = 0.001)
        {
            ITopologyContainer topologyContainer = (ITopologyContainer)FeatureDataset_Main;

            try//若不存在同名拓扑则添加
            {
                Topology = topologyContainer.get_TopologyByName(IN_TopoName);
                MessageBox.Show("已存在该拓扑。");
            }
            catch
            {
                try
                {
                    Topology = topologyContainer.CreateTopology(IN_TopoName, IN_Tolerance, -1, "");
                }
                catch (COMException comExc)
                {
                    MessageBox.Show(String.Format("拓扑创建出错: {0} 描述: {1}", comExc.ErrorCode, comExc.Message));
                }
            }
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// 在数据集中构建拓扑
        /// </summary>
        /// <param name="IN_TopoName">要生成拓扑的名称</param>
        /// <param name="IN_Tolerance">拓扑容差,可选,默认0.001</param>
        public void PUB_TopoBuild(string IN_TopoName, double IN_Tolerance = 0.001)
        {
            TP_topoName = IN_TopoName;
            ITopologyContainer topologyContainer = (ITopologyContainer)FeatureDataset_Main;

            try//若不存在同名拓扑则添加
            {
                Topology = topologyContainer.get_TopologyByName(IN_TopoName);
                CommonClass common = new CommonClass();
                common.DeleteTopolgyFromGISDB(Topology);
                DeleteFeature(TP_topoName);
            }
            catch
            {
            }
            try
            {
                Topology = topologyContainer.CreateTopology(IN_TopoName, IN_Tolerance, -1, "");
            }
            catch (COMException comExc)
            {
                MessageBox.Show(String.Format("拓扑创建出错: {0} 描述: {1}", comExc.ErrorCode, comExc.Message));
            }
        }
Пример #6
0
        /// <summary>
        /// 设置检查用到的拓扑
        /// </summary>
        private void SetCheckTopo()
        {
            #region 从MAP上获取其要素操作空间及数据集名称
            string            FeatureDataset_Name = "";    //要素数据集的名字
            IFeatureWorkspace pFeatureWorkspace;           //定义要素操作空间
            ///通过MAP上的图层获取我们所需要的数据集
            ILayer layer   = null;                         //定义用来接收指定组下面的图层
            int    L_count = _AppHk.MapControl.LayerCount; //MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            for (int G = 0; G < L_count; G++)
            {
                ILayer temp_layer = _AppHk.MapControl.get_Layer(G);
                //判别是不是组,如果是,就从组中取一个层
                if (temp_layer is IGroupLayer && temp_layer.Name == SetCheckState.CheckDataBaseName)
                {
                    ICompositeLayer grouplayer = temp_layer as ICompositeLayer;//把组图层转成组合图层
                    if (grouplayer.Count == 0)
                    {
                        return;
                    }
                    layer = grouplayer.get_Layer(0);//得到MAP中其中一个层
                    break;
                }
            }
            IFeatureLayer f_layer = layer as IFeatureLayer;
            IFeatureClass cl      = f_layer.FeatureClass;//得到对应的要素类
            if (cl.FeatureDataset == null)
            {
                SetCheckState.Message(pAppFormRef, "提示", "您所操作的数据是离散的,请先做数据预处理!");
                return;
            }
            else
            {
                pFeatureWorkspace   = cl.FeatureDataset.Workspace as IFeatureWorkspace;
                FeatureDataset_Name = cl.FeatureDataset.Name;//得到要素类的数据集名称
            }
            #endregion
            IFeatureDataset pfd = pFeatureWorkspace.OpenFeatureDataset(FeatureDataset_Name);//打开一个DATASET数据集

            IGeoDataset pGeoDataset = pfd as IGeoDataset;
            if (pGeoDataset != null)
            {
                SetCheckState.Geodatabase = pGeoDataset;
            }
            ITopologyContainer pTc = pfd as ITopologyContainer;//转成创建拓扑需要的对应对象接口
            #region 创建拓扑,后面的检查都使用这个拓扑
            if (SetCheckState.pT == null)
            {
                ITopology pT_temp = null;//定义一个临时的拓扑
                try
                {
                    if (SetCheckState.CheckDataBaseName == "更新修编数据" || SetCheckState.CheckDataBaseName == "工作库数据")
                    {
                        pT_temp = pTc.get_TopologyByName("Rule");//查找拓扑
                    }
                    else if (SetCheckState.CheckDataBaseName == "现势库数据")
                    {
                        pT_temp = pTc.get_TopologyByName("Rule1");//查找拓扑
                    }
                    if (pT_temp != null)
                    {
                        SetCheckState.pT        = pT_temp;//如果拓扑已存在,我们就把原先的拓扑赋值给定义的全局拓扑
                        SetCheckState.pRuleCont = SetCheckState.pT as ITopologyRuleContainer;
                    }
                }
                catch
                {
                    if (SetCheckState.CheckDataBaseName == "更新修编数据" || SetCheckState.CheckDataBaseName == "工作库数据")
                    {
                        SetCheckState.pT = pTc.CreateTopology("Rule", pTc.DefaultClusterTolerance, -1, "");//创建了个名叫Rule的拓扑。
                    }
                    else if (SetCheckState.CheckDataBaseName == "现势库数据")
                    {
                        SetCheckState.pT = pTc.CreateTopology("Rule1", pTc.DefaultClusterTolerance, -1, "");//创建了个名叫Rule的拓扑。
                    }
                    SetCheckState.pRuleCont = SetCheckState.pT as ITopologyRuleContainer;
                    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.Search(null, false).NextFeature() == null || pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    continue;
                                }
                                SetCheckState.pT.AddClass(pFeatureClass, 5, 1, 1, false);//将要验证的要线素类放入拓扑中。
                                #endregion
                            }
                            break;
                        }
                        #endregion
                    }
                }
            }
            #endregion
        }
Пример #7
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();
     }
 }
Пример #8
0
        private void Init()
        {
            this.m_ErrorCount   = 0;
            this.m_SucceedCount = 0;

            // 验证
            if (this.m_BaseWorkspace == null)
            {
                SendMessage(enumMessageType.Exception, "检查驱动的Base库没有设置,无法继续检查");
                return;
            }
            if (this.m_QueryWorkspace == null || this.m_QueryConnection == null)
            {
                SendMessage(enumMessageType.Exception, "检查驱动的Query库没有设置,无法继续检查");
                return;
            }

            // 结果库
            try
            {
                string strResultDBFile = this.m_ResultPath + "\\" + COMMONCONST.DB_Name_Result;
                System.IO.File.Copy(System.Windows.Forms.Application.StartupPath + "\\template\\report\\result_AutoTmpl.mdb", strResultDBFile, true);
                this.m_ResultConnection = Hy.Common.Utility.Data.AdoDbHelper.GetDbConnection(strResultDBFile);
            }
            catch (Exception exp)
            {
                SendMessage(enumMessageType.Exception, string.Format("创建结果库出错,信息:{0}", exp.Message));
                return;
            }

            // 创建规则实例,赋值,分类

            if (RuleInfos == null || RuleInfos.Count == 0)
            {
                return;
            }

            int count = RuleInfos.Count;

            m_NormalRuleList  = new List <ICheckRule>();
            m_TopoRuleList    = new List <ICheckRule>();
            m_DictRuleAndInfo = new Dictionary <ICheckRule, SchemaRule>();
            for (int i = 0; i < count; i++)
            {
                if (this.RuleInfos[i] == null || this.RuleInfos[i].ruleDllInfo == null)
                {
                    continue;
                }

                RuleInfo ruleInfo = new RuleInfo();// this.RuleInfos[i].ruleDllInfo;
                ruleInfo.ID            = this.RuleInfos[i].arrayRuleParas[0].strInstID;
                ruleInfo.Name          = this.RuleInfos[i].arrayRuleParas[0].strName;
                ruleInfo.Paramters     = this.RuleInfos[i].arrayRuleParas[0].pParas;
                ruleInfo.RuleClassInfo = this.RuleInfos[i].ruleDllInfo;
                ruleInfo.Description   = this.RuleInfos[i].strRemark;

                //if (ruleClassInfo == null)
                //    continue;

                if (ruleInfo.RuleClassInfo == null)
                {
                    SendMessage(enumMessageType.OperationalLog, string.Format("规则“{0}”无类信息,跳过检查", ruleInfo.Name));
                    continue;
                }

                ICheckRule checkRule = RuleFactory.CreateRuleInstance(ruleInfo.RuleClassInfo.DllName, ruleInfo.RuleClassInfo.ClassName);
                if (checkRule == null)
                {
                    SendMessage(enumMessageType.OperationalLog, string.Format("规则“{0}”反射未成功,跳过检查", ruleInfo.Name));
                    continue;
                }

                try
                {
                    // 参数设置
                    checkRule.BaseWorkspace    = this.m_BaseWorkspace;
                    checkRule.InstanceName     = ruleInfo.Name;
                    checkRule.InstanceID       = ruleInfo.ID;
                    checkRule.DefectLevel      = DefectHelper.GetRuleDefectLevel(ruleInfo.ID);
                    checkRule.MessageHandler   = this.m_Messager;
                    checkRule.QueryConnection  = this.m_QueryConnection;
                    checkRule.QueryWorkspace   = this.m_QueryWorkspace;
                    checkRule.TopoWorkspace    = this.m_TopoWorkspace;
                    checkRule.ResultConnection = this.m_ResultConnection;
                    checkRule.SchemaID         = this.m_SchemaID;
                    checkRule.SetParamters(ruleInfo.Paramters);

                    if (checkRule.ErrorType == enumErrorType.Topology)
                    {
                        if (m_Topology == null)
                        {
                            try
                            {
                                // 先创建Topo库(空库)和结果库
                                if (System.IO.Directory.Exists(this.m_TopoDBPath + "\\" + COMMONCONST.DB_Name_Topo))
                                {
                                    System.IO.Directory.Delete(this.m_TopoDBPath + "\\" + COMMONCONST.DB_Name_Topo, true);
                                }
                                Hy.Common.Utility.Esri.AEAccessFactory.CreateFGDB(this.m_TopoDBPath, COMMONCONST.DB_Name_Topo, ref this.m_TopoWorkspace);
                                if (this.m_TopoWorkspace == null)
                                {
                                    SendMessage(enumMessageType.Exception, "创建拓扑库失败");
                                }

                                // 根据Base库找第一个Geodataset的空间参考,用来创建拓扑库
                                ISpatialReference topoSptatialRef = null;
                                IEnumDataset      enDataset       = this.m_BaseWorkspace.get_Datasets(esriDatasetType.esriDTAny);
                                IDataset          ds = enDataset.Next();
                                while (ds != null)
                                {
                                    if (ds is IGeoDataset)
                                    {
                                        topoSptatialRef = (ds as IGeoDataset).SpatialReference;
                                        break;
                                    }
                                    ds = enDataset.Next();
                                }
                                IFeatureDataset fDataset = (this.m_TopoWorkspace as IFeatureWorkspace).CreateFeatureDataset(COMMONCONST.Dataset_Name, topoSptatialRef);
                                if (fDataset == null)
                                {
                                    SendMessage(enumMessageType.Exception, "创建拓扑库Dataset失败");
                                }

                                ITopologyContainer topoContainer = fDataset as ITopologyContainer;
                                //m_Topology = topoContainer.get_TopologyByName(COMMONCONST.Topology_Name);    // 若已有Topology,则不再创建

                                //if (m_Topology == null)
                                m_Topology = topoContainer.CreateTopology(COMMONCONST.Topology_Name, this.m_TopoTolerance, COMMONCONST.TopoError_MaxCount, "esriConfigurationKeywordTopology");
                            }
                            catch (Exception exp)
                            {
                                SendMessage(enumMessageType.Exception, "创建Topology出错,信息:" + exp.ToString());
                            }
                        }
                        (checkRule as ITopologicalRule).Topology = m_Topology;

                        m_TopoRuleList.Add(checkRule);
                    }
                    else
                    {
                        m_NormalRuleList.Add(checkRule);
                    }
                    //m_RuleList.Add(checkRule);
                    m_DictRuleAndInfo.Add(checkRule, this.RuleInfos[i]);
                }
                catch (Exception ex)
                {
                    SendMessage(enumMessageType.Exception, "初始化规则失败,信息:" + ex.ToString());
                    continue;
                }
            }
        }