Exemplo n.º 1
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;
            }
        }
        /// <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;
            }
        }
        /// <summary>
        /// 点重复数字化检查主函数
        /// </summary>
        /// <param name="_AppHk"></param>
        private void ExcutePointDigitalDuplicateCheck(object Hook)
        {
            Plugin.Application.IAppGISRef _AppHk = Hook as Plugin.Application.IAppGISRef;

            #region 取得进度条对象

            //取得进度条对象

            Plugin.Application.IAppFormRef pAppForm = _AppHk as Plugin.Application.IAppFormRef;
            #endregion
            System.Data.DataTable Datatable = new System.Data.DataTable(); //手动建立一个数据表,将得到的数据邦定到检查结果当中显示
            Datatable.Columns.Add("重复点", typeof(string));                  //创建一列

            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();
            ClearGrid.Operate(pAppForm, _AppHk);
            //判断图层个数是否为0
            if (_AppHk.MapControl.LayerCount == 0)
            {
                return;
            }
            SetCheckState.CheckShowTips(pAppForm, "重复点检查开始.....");
            int Count = _AppHk.MapControl.LayerCount;
            for (int i = 0; i < Count; i++)
            {
                ILayer temp_layer = _AppHk.MapControl.get_Layer(i);
                //判别是不是组,如果是,就从组中取一个层
                if (temp_layer is IGroupLayer && temp_layer.Name == SetCheckState.CheckDataBaseName)
                {
                    ICompositeLayer grouplayer = temp_layer as ICompositeLayer; //把组图层转成组合图层
                    int             C_count    = grouplayer.Count;              //组合图层数
                    if (C_count == 0)
                    {
                        return;
                    }
                    #region 遍历组下面的重复点
                    ArrayList LayerList = new ArrayList();//存要素类
                    //将所有可用的图层存入动态数组
                    for (int c = 0; c < C_count; c++)
                    {
                        //图层转换
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { C_count, 0, 1, c, pAppForm }); //给进度条传需要的值
                        int num = c + 1;                                                                                          //由于层的索引是从0开始的,所以得加1
                        ESRI.ArcGIS.Carto.ILayer        pLayer     = grouplayer.get_Layer(c);
                        ESRI.ArcGIS.Carto.IFeatureLayer pFeatLayer = pLayer as ESRI.ArcGIS.Carto.IFeatureLayer;
                        //如果图层不为空,就转成对应的要素类
                        if (pFeatLayer == null)
                        {
                            continue;
                        }
                        IFeatureClass pFeatureClass = pFeatLayer.FeatureClass;
                        if (pFeatureClass == null)
                        {
                            continue;
                        }
                        //只取点层
                        if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPoint && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation)
                        {
                            LayerList.Add(pFeatureClass);//加入动态数组中
                        }
                    }
                    SetCheckState.TreeIni_Fun(LayerList, _AppHk);//初始化树
                    //重复点检查操作
                    for (int L = 0; L < LayerList.Count; L++)
                    {
                        IFeatureClass pFeatureClass = LayerList[L] as IFeatureClass;
                        RePoint(pFeatureClass, pAppForm, Datatable, L);//开始遍历重复点
                        if (L == LayerList.Count - 1)
                        {
                            SetCheckState.CheckShowTips(pAppForm, "重复点检查马上完成,请稍后...");
                        }
                    }
                    #endregion
                    break;
                }
            }
            pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //是否显示进度条,加载让它显示
            SetCheckState.CheckShowTips(pAppForm, "重复点检查完成!");
            _AppHk.CurrentThread = null;                                                                     //线程使用完置空

            pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });
            SetCheckState.Message(pAppForm, "提示", "重复点检查完成!");
            //选中检查出错列表
            ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
        }