提取拓扑错误并导出

将Arcengine拓扑错误的要素提取出来并导出为shape文件


拓扑错误提取:

  private void PRV_GetErrorFeature(ITopologyRule IN_TopologyRule)
        {
            IEnvelope Temp_Envolope = (TP_MainTopology as IGeoDataset).Extent;
            IErrorFeatureContainer Temp_ErrorContainer = TP_MainTopology as IErrorFeatureContainer;
            //获取该种错误所有的错误要素
            IEnumTopologyErrorFeature Temp_EnumErrorFeature = Temp_ErrorContainer.get_ErrorFeatures(((IGeoDataset)FDS_MainFeatureDataset).SpatialReference, IN_TopologyRule, Temp_Envolope, true, true);
            //提取一个错误要素
            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;
                //以模型要素为模板构建一个要素类
                FDS_MainFeatureDataset.CreateFeatureClass(IN_TopologyRule.ToString(), Temp_MoudleFeature.Fields, Temp_ObjectClassDescription.InstanceCLSID, Temp_ObjectClassDescription.ClassExtensionCLSID, Temp_MoudleFeature.FeatureType, "Shape", "");
                //打开生成的目标要素类并加入集合留待输出时使用
                IFeatureClass Temp_TargetFeatureClass = (FDS_MainFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(IN_TopologyRule.ToString());
                LI_TopoErrorFeatureClass.Add(Temp_TargetFeatureClass);
                //将所有错误要素添加进目标要素类
                IWorkspaceEdit Temp_WorkspaceEdit = (IWorkspaceEdit)FDS_MainFeatureDataset.Workspace;
                Temp_WorkspaceEdit.StartEditing(true);
                Temp_WorkspaceEdit.StartEditOperation();
                IFeatureBuffer Temp_FeatureBuffer = Temp_TargetFeatureClass.CreateFeatureBuffer();
                //在目标要素类中插入所有错误要素
                IFeatureCursor featureCursor = Temp_TargetFeatureClass.Insert(true); ;
                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(5, Temp_ErrorFeature.TopologyRuleType);
                    Temp_FeatureBuffer.Shape = Temp_Feature.Shape;
                    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);
            }
        }

其中:

TP_MainTopology为验证后的拓扑,类行为ITopology

  LI_TopoErrorFeatureClass为记录所有拓扑错误要素类的集合,类型为  List<IFeatureClass> LI_TopoErrorFeatureClass

FDS_MainFeatureDataset为存储要素类的要素数据集,类型为FeatureDataset


输出shape文件


        private void PRV_OutPutToShape()
        {
            FeatureClassToShapefile GP_FeatureClassToShape = new FeatureClassToShapefile();
            foreach (IFeatureClass Each_FeatureClass in LI_TopoErrorFeatureClass)
            {
                GP_FeatureClassToShape.Input_Features = Each_FeatureClass;
                GP_FeatureClassToShape.Output_Folder = "E:\\";
                GP_Tool.Execute(GP_FeatureClassToShape,null);
            }
                    
        }



你可能感兴趣的:(arcgis,ArcEngine,ArcgisEngine,ae)