Beispiel #1
0
        /// <summary>
        /// 导出拓扑错误图形, 在指定要素类中保存扑错误图形
        /// </summary>
        /// <param name="workespace"></param>
        /// <param name="topoDatasetName"></param>
        /// <param name="topoName"></param>
        /// <param name="envelope"></param>
        /// <param name="shpFeatureClass"></param>
        /// <returns></returns>
        public static IFeatureClass TopoErrorToNewFeatureClass(this IWorkspace workespace, string topoDatasetName,
                                                               string topoName, IEnvelope envelope, IFeatureClass shpFeatureClass)
        {
            //获得拓扑
            var topology = GetTopologyByName(workespace as IFeatureWorkspace, topoDatasetName, topoName);

            //打开编辑并验证拓扑
            workespace.StartEdit(() => topology.ValidateTopology(envelope));

            IErrorFeatureContainer errorFeatureContainer = (IErrorFeatureContainer)topology;
            ISpatialReference      spatialReference      = ((IGeoDataset)topology).SpatialReference;

            IWorkspace shpWorkspace = (shpFeatureClass as IDataset).Workspace;

            shpWorkspace.StartEdit(() =>
            {
                var topoRules = GetTopologyRules(topology);
                foreach (ITopologyRule rule in topoRules)
                {
                    IEnumTopologyErrorFeature enumTopologyErrorFeature = errorFeatureContainer.get_ErrorFeatures(spatialReference, rule, envelope, true, true);
                    ITopologyErrorFeature topologyErrorFeature         = null;
                    while ((topologyErrorFeature = enumTopologyErrorFeature.Next()) != null)
                    {
                        IFeature errorFeature = shpFeatureClass.CreateFeature();
                        errorFeature.Shape    = (topologyErrorFeature as IFeature).ShapeCopy;
                        errorFeature.Store();
                    }
                }
            });
            return(shpFeatureClass);
        }
Beispiel #2
0
        //获取错误信息
        private void PRV_GetError(ITopologyRule IN_TopologyRule)
        {
            if (Topology != null)
            {
                IEnvelope Temp_Envolope = (this.Topology as IGeoDataset).Extent;
                IErrorFeatureContainer Temp_ErrorContainer = Topology as IErrorFeatureContainer;
                //获取所有信息
                IEnumTopologyErrorFeature Temp_EnumErrorFeature = Temp_ErrorContainer.get_ErrorFeatures(((IGeoDataset)FeatureDataset_Main).SpatialReference, IN_TopologyRule, Temp_Envolope, true, true);
                ITopologyErrorFeature     Temp_ErrorFeature     = Temp_EnumErrorFeature.Next();
                while (Temp_ErrorFeature != null)
                {
                    IFeature Temp_Feature = Temp_ErrorFeature as IFeature;
                    string   Temp_ErrorInfo;
                    if (Temp_ErrorFeature.DestinationClassID != 0)//检测是否是双要素规则
                    {
                        Temp_ErrorInfo = Temp_ErrorFeature.OriginOID + "," + Temp_ErrorFeature.DestinationOID;
                    }
                    else
                    {
                        Temp_ErrorInfo = Temp_ErrorFeature.OriginOID.ToString();
                    }
                    LI_AllErrorInfo.Add((PRV_RecorverTopologyRuleType((int)(Temp_ErrorFeature.TopologyRuleType))) + " " + Temp_ErrorInfo);//将错误信息加入List

                    //MessageBox.Show("错误:" + PRV_RecorverTopologyRuleType((int)(Temp_ErrorFeature.TopologyRuleType)) + "\r\n错误ID:" + Temp_ErrorInfo);
                    Temp_ErrorFeature = Temp_EnumErrorFeature.Next();
                }
            }
            else
            {
                MessageBox.Show("请先构建拓扑");
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获取指定类型的拓扑错误要素枚举
        /// </summary>
        /// <param name="topologyRule">拓扑规则</param>
        /// <param name="topology">拓扑</param>
        /// <returns></returns>
        public static IEnumTopologyErrorFeature GetEnumTopoErrorFeature(this ITopologyRule topologyRule, ITopology topology)
        {
            IEnvelope envelope = (topology as IGeoDataset).Extent;
            IErrorFeatureContainer errorContainer = topology as IErrorFeatureContainer;

            IEnumTopologyErrorFeature enumErrorFeature = errorContainer.get_ErrorFeatures(
                ((IGeoDataset)topology.FeatureDataset).SpatialReference, topologyRule, envelope, true, true);

            return(enumErrorFeature);
        }
Beispiel #4
0
        public override void OnMouseUp(int int_0, int int_1, int int_2, int int_3)
        {
            IActiveView focusMap;
            double      mapUnits;

            if (this.bool_0)
            {
                IEnvelope envelope = null;
                if (this.idisplayFeedback_0 != null)
                {
                    envelope = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                    if ((envelope.IsEmpty || envelope.Width == 0 ? true : envelope.Height == 0))
                    {
                        focusMap        = this._context.FocusMap as IActiveView;
                        envelope        = this.ipoint_0.Envelope;
                        mapUnits        = Common.ConvertPixelsToMapUnits(focusMap, 8);
                        envelope.Height = mapUnits;
                        envelope.Width  = mapUnits;
                        envelope.CenterAt(this.ipoint_0);
                    }
                }
                else
                {
                    focusMap        = this._context.FocusMap as IActiveView;
                    envelope        = this.ipoint_0.Envelope;
                    mapUnits        = Common.ConvertPixelsToMapUnits(focusMap, 8);
                    envelope.Height = mapUnits;
                    envelope.Width  = mapUnits;
                    envelope.CenterAt(this.ipoint_0);
                }
                envelope.SpatialReference = this._context.FocusMap.SpatialReference;


                IActiveView               activeView              = this._context.FocusMap as IActiveView;
                IErrorFeatureContainer    topology                = CmdSelectTopology.m_TopologyLayer.Topology as IErrorFeatureContainer;
                IGeoDataset               geoDataset              = CmdSelectTopology.m_TopologyLayer.Topology as IGeoDataset;
                ITopologyErrorSelection   mTopologyLayer          = CmdSelectTopology.m_TopologyLayer as ITopologyErrorSelection;
                IEnumTopologyErrorFeature errorFeaturesByRuleType = topology.ErrorFeaturesByRuleType[geoDataset.SpatialReference, esriTopologyRuleType.esriTRTAny, envelope, mTopologyLayer.SelectErrors, mTopologyLayer.SelectExceptions];
                FixTopologyErrorTool.m_pTopoErroeSelection.Clear();
                for (ITopologyErrorFeature i = errorFeaturesByRuleType.Next(); i != null; i = errorFeaturesByRuleType.Next())
                {
                    FixTopologyErrorTool.m_pTopoErroeSelection.Add(new TopologyError(CmdSelectTopology.m_TopologyLayer, i));
                }
                this.method_0();
                activeView.Refresh();
                this.idisplayFeedback_0 = null;
                this.bool_0             = false;
            }
        }
        /// <summary>
        /// 重复线
        /// </summary>
        private void Line_redo(object para)
        {
            Plugin.Application.IAppFormRef pAppForm  = para 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 && 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.esriGeometryPolyline && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                        break;
                    }
                    #endregion
                }
                #endregion
                SetCheckState.CheckShowTips(pAppForm, "数据准备完毕,准备进度显示数据,请稍后.....");
                #region 通过过滤后的要素类来进行拓扑检查
                int Count = list_line.Count;//总要遍历的层数
                if (Count == 0)
                {
                    _AppHk.CurrentThread = null;
                    SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!");
                    SetCheckState.Message(pAppForm, "提示", "线重复检查完成!");
                    //选中检查出错列表
                    ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树
                SetCheckState.CheckShowTips(pAppForm, "进度数据准备完毕,马上进入拓扑分析,请稍后.....");
                for (int N = 0; N < Count; N++)
                {
                    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.esriTRTLineNoOverlap; //使用规则的类型(线不重叠)
                    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); //将所有的拓扑出错进行枚举
                    int num = N + 1;                                                                                                                                         //由于层的索引是从0开始的,所以得加1

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();                                                                                            //开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    //将当前层的所有出错要素放入动态数组当中
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    SetCheckState.CheckShowTips(pAppForm, "拓扑分析完毕,进行具体检查操作,请稍后.....");
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "无重复线准备进行下一个图层操作,请稍后....");
                        continue;
                    }
                    SetCheckState.CheckShowTips(pAppForm, "正在进行" + TempClass.AliasName + "图层操作,请稍后....");
                    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);                                           //目标要素

                        ///求几何空间差值,必须要两种情况考虑: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)
                        {
                            StringBuilder origin_temp      = new StringBuilder(); //除了SHAPE外的字段对比源
                            StringBuilder destination_temp = new StringBuilder(); //除了SHAPE外的字段对比目标

                            ArrayList list  = Foreach();                          //得到我们需要遍历的对比字段
                            int       count = list.Count;
                            if (count > 0)
                            {
                                for (int n = 0; n < count; n++)
                                {
                                    int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString());       //查看我们要对比的字段名是不是存在 源

                                    int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString()); //查看我们要对比的字段名是不是存在 目标
                                    if (index >= 0 && index1 >= 0)
                                    {
                                        origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index));
                                        destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1));
                                    }
                                }
                                if (origin_temp.Equals(destination_temp) && origin_temp != null && destination_temp != null)
                                {
                                    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);
                                }
                                else
                                {
                                    pTopoErrFeat = pEnumTopoErrFeat.Next();
                                    continue;
                                }
                            }
                            else
                            {
                                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);
                            }
                        }
                    }
                    #endregion

                    pRuleCont.DeleteRule(topologyRule);//移除拓扑规则

                    if (num == Count)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "重复线检查马上完成,请稍后....");
                        break;
                    }
                }
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //显示完成隐藏进度条
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件进行方法的委托,因为得让它成为安全的
                _AppHk.CurrentThread = null;                                                                     //将线程置空
                SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!");
                SetCheckState.Message(pAppForm, "提示", "线重复检查完成!");
                //选中检查出错列表
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                #endregion
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;//将线程置空
                MessageBox.Show(ex.ToString());
                return;
            }
        }
        /// <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[] { "提示", "处理完毕!" });
        }
Beispiel #7
0
        /// <summary>
        /// 创建拓扑
        /// </summary>
        /// <param name="workspaceName">被检查文件的路径名称</param>
        public void CreateTopology(string workspaceName)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory   workspaceFactory  = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace          workspace         = workspaceFactory.OpenFromFile(Application.StartupPath + @"\Convert\GeoDataBase.gdb", 0);
            IFeatureWorkspace   featureWorkspace  = (IFeatureWorkspace)workspace;
            IFeatureDataset     featureDataset    = featureWorkspace.OpenFeatureDataset("ContourData");
            ITopologyContainer2 topologyContainer = (ITopologyContainer2)featureDataset;
            IFeatureClass       CurrContour       = null;

            try
            {
                CurrContour = featureWorkspace.OpenFeatureClass("CurrContour");
                ITopology topology = topologyContainer.get_TopologyByName("eeee");
                IDataset  fDataset = (IDataset)topology;
                fDataset.Delete();
            }
            catch (Exception)
            {
                // throw;
            }

            if (CurrContour != null)
            {
                IDataset fDataset = (IDataset)CurrContour;

                fDataset.Delete();
            }

            Geoprocessor gp = new Geoprocessor();
            FeatureClassToFeatureClass pFFeatureClassToFeatureClass = new FeatureClassToFeatureClass();

            pFFeatureClassToFeatureClass.in_features = Application.StartupPath + "\\Convert\\ContourResult\\" + workspaceName + "\\Contour.shp";
            pFFeatureClassToFeatureClass.out_path    = Application.StartupPath + "\\Convert\\GeoDataBase.gdb\\ContourData";

            pFFeatureClassToFeatureClass.out_name = "CurrContour";


            IGeoProcessorResult geoProcessorResult = (IGeoProcessorResult)gp.Execute(pFFeatureClassToFeatureClass, null);

            CurrContour = featureWorkspace.OpenFeatureClass("CurrContour");

            ISchemaLock schemaLock = (ISchemaLock)featureDataset;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Create the topology.

                ITopology topology = topologyContainer.CreateTopology("eeee",
                                                                      topologyContainer.DefaultClusterTolerance, -1, "");

                // Add feature classes and rules to the topology.
                topology.AddClass((IClass)CurrContour, 5, 1, 1, false);

                AddRuleToTopology(topology, esriTopologyRuleType.esriTRTLineNoIntersection,
                                  "must not intersect", CurrContour);

                int ErrorCount = 0;

                // Get an envelope with the topology's extents and validate the topology.
                IGeoDataset geoDataset = (IGeoDataset)topology;
                ESRI.ArcGIS.Geometry.IEnvelope envelope = geoDataset.Extent;
                ValidateTopology(topology, envelope);
                IGeoDataset               geoDS          = topology as IGeoDataset;
                IErrorFeatureContainer    errorContainer = topology as IErrorFeatureContainer;
                IEnumTopologyErrorFeature eErrorFeat;
                eErrorFeat = errorContainer.get_ErrorFeaturesByRuleType(geoDS.SpatialReference,
                                                                        esriTopologyRuleType.esriTRTAreaNoGaps, null, true, false);
                ITopologyErrorFeature topoError;
                topoError = eErrorFeat.Next();
                while (topoError != null)
                {
                    ErrorCount++;
                    topoError = eErrorFeat.Next();
                }
                if (ErrorCount == 0)
                {
                    MessageBox.Show("无拓扑错误!", "Sunz", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("拓扑错误" + "" + ErrorCount + "" + "个!");
                }
            }
            catch (COMException comExc)
            {
                throw new Exception(String.Format(
                                        "Error creating topology: {0} Message: {1}", comExc.ErrorCode,
                                        comExc.Message), comExc);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
        /// <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;
            }
        }
Beispiel #9
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;
            }
        }
Beispiel #10
0
        private void PRV_GetErrorFeature()
        {
            foreach (ITopologyRule IN_RuleType in LI_ITopologyRule)
            {
                int tempCount = 0;
                DicTopoError.Add(IN_RuleType.OriginSubtype.ToString(), tempCount);
                IEnvelope Temp_Envolope = (this.Topology as IGeoDataset).Extent;
                IErrorFeatureContainer Temp_ErrorContainer = Topology as IErrorFeatureContainer;
                //获取该种错误所有的错误要素
                IEnumTopologyErrorFeature Temp_EnumErrorFeature = Temp_ErrorContainer.get_ErrorFeatures(((IGeoDataset)FeatureDataset_Main).SpatialReference, IN_RuleType, Temp_Envolope, true, false);
                //提取一个错误要素
                ITopologyErrorFeature Temp_ErrorFeature = Temp_EnumErrorFeature.Next();
                if (Temp_ErrorFeature != null)
                {
                    //作为搭建模型的要素
                    IFeature Temp_MoudleFeature = Temp_ErrorFeature as IFeature;
                    //生成要素类需要CLSID和EXCLSID
                    IFeatureClassDescription Temp_FeatureClassDescription = new FeatureClassDescriptionClass();
                    IObjectClassDescription  Temp_ObjectClassDescription  = (IObjectClassDescription)Temp_FeatureClassDescription;
                    //以模型要素为模板构建一个要素类
                    //FeatureDataset_Main.CreateFeatureClass(TP_topoName, Temp_MoudleFeature.Fields, Temp_ObjectClassDescription.InstanceCLSID, Temp_ObjectClassDescription.ClassExtensionCLSID, Temp_MoudleFeature.FeatureType, "Shape", null);
                    //打开生成的目标要素类并加入集合留待输出时使用
                    IFeatureClass Temp_TargetFeatureClass;
                    string        ErrorFeatureName = TP_topoName + "_" + Temp_ErrorFeature.ShapeType.ToString();
                    try
                    {
                        Temp_TargetFeatureClass = (FeatureDataset_Main.Workspace as IFeatureWorkspace).OpenFeatureClass(ErrorFeatureName);
                    }
                    catch
                    {
                        FeatureDataset_Main.CreateFeatureClass(ErrorFeatureName, Temp_MoudleFeature.Fields, Temp_ObjectClassDescription.InstanceCLSID, Temp_ObjectClassDescription.ClassExtensionCLSID, Temp_MoudleFeature.FeatureType, "Shape", null);
                        Temp_TargetFeatureClass = (FeatureDataset_Main.Workspace as IFeatureWorkspace).OpenFeatureClass(ErrorFeatureName);
                    }
                    LI_TopoErrorFeatureClass.Add(Temp_TargetFeatureClass);
                    //将所有错误要素添加进目标要素类
                    IWorkspaceEdit Temp_WorkspaceEdit = (IWorkspaceEdit)FeatureDataset_Main.Workspace;
                    Temp_WorkspaceEdit.StartEditing(true);
                    Temp_WorkspaceEdit.StartEditOperation();
                    IFeatureBuffer Temp_FeatureBuffer = Temp_TargetFeatureClass.CreateFeatureBuffer();

                    //在目标要素类中插入所有错误要素
                    IFeatureCursor featureCursor = Temp_TargetFeatureClass.Insert(false);
                    while (Temp_ErrorFeature != null)
                    {
                        IFeature Temp_Feature = Temp_ErrorFeature as IFeature;
                        //给目标要素附属性
                        Temp_FeatureBuffer.set_Value(1, Temp_ErrorFeature.OriginClassID);
                        Temp_FeatureBuffer.set_Value(2, Temp_ErrorFeature.OriginOID);
                        Temp_FeatureBuffer.set_Value(3, Temp_ErrorFeature.DestinationClassID);
                        Temp_FeatureBuffer.set_Value(4, Temp_ErrorFeature.DestinationOID);
                        Temp_FeatureBuffer.set_Value(5, Temp_ErrorFeature.TopologyRuleType);
                        Temp_FeatureBuffer.set_Value(8, Temp_ErrorFeature.IsException);
                        Temp_FeatureBuffer.Shape = Temp_Feature.Shape;
                        if (this.DicTopoData.ContainsKey(IN_RuleType.OriginSubtype.ToString()))
                        {
                            if (IN_RuleType.Name == "面要素之间无空隙")
                            {
                                IArea pArea = (IArea)Temp_Feature.Shape.Envelope;
                                if (pArea.Area < System.Convert.ToDouble(this.DicTopoData[IN_RuleType.OriginSubtype.ToString()]))
                                {
                                    tempCount++;
                                    DicTopoError[IN_RuleType.OriginSubtype.ToString()] = tempCount;
                                    object featureOID = featureCursor.InsertFeature(Temp_FeatureBuffer);
                                    featureCursor.Flush();//保存要素
                                }
                            }
                        }
                        else
                        {
                            tempCount++;
                            DicTopoError[IN_RuleType.OriginSubtype.ToString()] = tempCount;
                            object featureOID = featureCursor.InsertFeature(Temp_FeatureBuffer);
                            featureCursor.Flush();//保存要素
                        }
                        Temp_ErrorFeature = Temp_EnumErrorFeature.Next();
                    }
                    Temp_WorkspaceEdit.StopEditOperation();
                    Temp_WorkspaceEdit.StopEditing(true);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
                }
            }
        }
Beispiel #11
0
        private bool InsertTopoError(IFeatureClass destFClass)
        {
            try
            {
                string strSQL = @"SELECT
                            b.CheckType,
                            IIF(b.TargetFeatClass1 is Null,'',b.TargetFeatClass1) as YSTC,
                            IIF(a.SourceBSM is Null,'',a.SourceBSM) as SourceBSM,
                            IIF(a.MBTC is Null,'',a.MBTC) as MBTC,
                            IIF(a.TargetBSM is Null,'',a.TargetBSM) as BSM2,
                            a.TPTC as TopoLayerName,
                            a.Reason as Description,
                            a.IsException as IsException,
                            IIf(a.Remark is Null,'',a.Remark) as Remark,
                            b.GZBM ,
                            a.ArcGisRule as ArcGisRule,
                            a.JHLX as JHLX,
                            a.SourceLayerID,
                            a.TargetLayerID,
                            a.SourceOID as OID,
                            a.TargetOID as OID2
                            from LR_ResAutoTopo as a, LR_ResultEntryRule as b where a.RuleInstID=b.RuleInstID
                            ";


                DataTable dtError = Hy.Common.Utility.Data.AdoDbHelper.GetDataTable(this.ResultConnection, strSQL);

                IFeatureCursor        fCusorInsert   = destFClass.Insert(false);
                Dictionary <int, int> dictFieldIndex = new Dictionary <int, int>();
                for (int i = 0; i < m_FieldCaptions.Count; i++)
                {
                    dictFieldIndex.Add(i, destFClass.FindField(m_FieldCaptions[i]));
                }
                int xFieldIndex = destFClass.FindField("X坐标");
                int yFieldIndex = destFClass.FindField("Y坐标");

                IErrorFeatureContainer errFeatureContainer = this.Topology as IErrorFeatureContainer;
                ISpatialReference      spatialRef          = (this.Topology as IGeoDataset).SpatialReference;
                for (int i = 0; i < dtError.Rows.Count; i++)
                {
                    DataRow              rowError  = dtError.Rows[i];
                    int                  fClassID  = Convert.ToInt32(rowError["SourceLayerID"]);
                    int                  fClassID2 = Convert.ToInt32(rowError["TargetLayerID"]);
                    int                  oid       = Convert.ToInt32(rowError["OID"]);
                    int                  oid2      = Convert.ToInt32(rowError["OID2"]);
                    esriGeometryType     geoType   = (esriGeometryType)Convert.ToInt32(rowError["JHLX"]);
                    esriTopologyRuleType ruleType  = (esriTopologyRuleType)Convert.ToInt32(rowError["ArcGISRule"]);

                    IFeature srcFeature = errFeatureContainer.get_ErrorFeature(spatialRef, ruleType, geoType, fClassID, fClassID2, oid, oid2) as IFeature;

                    IFeatureBuffer fNew = destFClass.CreateFeatureBuffer();
                    for (int j = 0; j < m_FieldCaptions.Count; j++)
                    {
                        int fIndex = dictFieldIndex[j];
                        if (fIndex < 0)
                        {
                            continue;
                        }

                        fNew.set_Value(fIndex, rowError[j]);
                    }
                    fNew.Shape = GetErrorGeometry(srcFeature);
                    IPoint point = fNew.Shape as IPoint;
                    fNew.set_Value(xFieldIndex, point.X);
                    fNew.set_Value(yFieldIndex, point.Y);

                    fCusorInsert.InsertFeature(fNew);

                    if (i % 2000 == 0)
                    {
                        fCusorInsert.Flush();
                    }
                }

                fCusorInsert.Flush();

                return(true);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());
                return(false);
            }
        }
Beispiel #12
0
        private IFeature GetFeature(DataRow rowError, string strLayerName)
        {
            IMap theMap = this.m_HookHelper.FocusMap;
            MapLayersController mapController = new MapLayersController(theMap);
            enumErrorType       errType       = (enumErrorType)Convert.ToInt32(rowError["ErrorType"]);

            switch (errType)
            {
            case enumErrorType.Topology:
            {
                ITopologyLayer topoLayerTarget = mapController.GetLayer(strLayerName) as ITopologyLayer;
                if (topoLayerTarget == null)
                {
                    return(null);
                }

                ITopology topology = topoLayerTarget.Topology;
                IErrorFeatureContainer errFeatureContainer = topology as IErrorFeatureContainer;
                esriTopologyRuleType   ruleType            = (esriTopologyRuleType)Convert.ToInt32(rowError[Field_Name_TopologyRuleType]);
                //string strGeoType = rowError[Field_Name_TopologyGeometryType] as string;
                //esriGeometryType geoType = (strGeoType == "点" ? esriGeometryType.esriGeometryPoint : (strGeoType == "线" ? esriGeometryType.esriGeometryLine : esriGeometryType.esriGeometryPolygon));
                esriGeometryType geoType = (esriGeometryType)Convert.ToInt32(rowError[Field_Name_TopologyGeometryType]);
                int sourceClassID        = (int)rowError["SourceLayerID"];
                int sourceOID            = (int)rowError["OID"];
                int targetClassID        = (int)rowError["TargetLayerID"];
                int targetOID            = Convert.ToInt32(rowError["OID2"]);

                return(errFeatureContainer.get_ErrorFeature((topology as IGeoDataset).SpatialReference, ruleType, geoType, sourceClassID, sourceOID, targetClassID, targetOID) as IFeature);
            }
            break;

            case enumErrorType.Normal:
            {
                IFeatureLayer flyrTarget = mapController.GetLayer(strLayerName) as IFeatureLayer;
                if (flyrTarget == null)
                {
                    return(null);
                }

                // 改为优先从OID查找定位
                if (rowError.Table.Columns.Contains(Field_Name_TargetOID) && rowError[Field_Name_TargetOID] != DBNull.Value)
                {
                    return(flyrTarget.FeatureClass.GetFeature((int)rowError[Field_Name_TargetOID]));
                }
                else if (rowError.Table.Columns.Contains(Field_Name_TargetBSM) && !string.IsNullOrEmpty(rowError[Field_Name_TargetBSM] as string))
                {
                    IQueryFilter qFilter    = new QueryFilterClass();
                    IFields      fields     = flyrTarget.FeatureClass.Fields;
                    int          fieldIndex = fields.FindField("BSM");
                    if (fieldIndex < 0)
                    {
                        return(null);
                    }

                    IField bsmField = fields.get_Field(fieldIndex);
                    if (bsmField.Type == esriFieldType.esriFieldTypeInteger)
                    {
                        qFilter.WhereClause = string.Format("BSM={0}", rowError[Field_Name_TargetBSM]);
                    }
                    else
                    {
                        qFilter.WhereClause = string.Format("BSM='{0}'", rowError[Field_Name_TargetBSM]);
                    }
                    IFeatureCursor fCursor = flyrTarget.FeatureClass.Search(qFilter, false);

                    return(fCursor.NextFeature());
                }
                else
                {
                    return(null);
                }
            }

            default: return(null);
            }
        }
Beispiel #13
0
        /// <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;
            }
        }