提取拓扑错误并导出

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

拓扑错误提取:

[csharp]  view plain  copy
 
  1. private void PRV_GetErrorFeature(ITopologyRule IN_TopologyRule)  
  2.       {  
  3.           IEnvelope Temp_Envolope = (TP_MainTopology as IGeoDataset).Extent;  
  4.           IErrorFeatureContainer Temp_ErrorContainer = TP_MainTopology as IErrorFeatureContainer;  
  5.           //获取该种错误所有的错误要素  
  6.           IEnumTopologyErrorFeature Temp_EnumErrorFeature = Temp_ErrorContainer.get_ErrorFeatures(((IGeoDataset)FDS_MainFeatureDataset).SpatialReference, IN_TopologyRule, Temp_Envolope, truetrue);  
  7.           //提取一个错误要素  
  8.           ITopologyErrorFeature Temp_ErrorFeature = Temp_EnumErrorFeature.Next();  
  9.           if (Temp_ErrorFeature != null)  
  10.           {  
  11.               //作为搭建模型的要素  
  12.               IFeature Temp_MoudleFeature = Temp_ErrorFeature as IFeature;  
  13.               //生成要素类需要CLSID和EXCLSID  
  14.               IFeatureClassDescription Temp_FeatureClassDescription = new FeatureClassDescriptionClass();  
  15.               IObjectClassDescription Temp_ObjectClassDescription = (IObjectClassDescription)Temp_FeatureClassDescription;  
  16.               //以模型要素为模板构建一个要素类  
  17.               FDS_MainFeatureDataset.CreateFeatureClass(IN_TopologyRule.ToString(), Temp_MoudleFeature.Fields, Temp_ObjectClassDescription.InstanceCLSID, Temp_ObjectClassDescription.ClassExtensionCLSID, Temp_MoudleFeature.FeatureType, "Shape""");  
  18.               //打开生成的目标要素类并加入集合留待输出时使用  
  19.               IFeatureClass Temp_TargetFeatureClass = (FDS_MainFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(IN_TopologyRule.ToString());  
  20.               LI_TopoErrorFeatureClass.Add(Temp_TargetFeatureClass);  
  21.               //将所有错误要素添加进目标要素类  
  22.               IWorkspaceEdit Temp_WorkspaceEdit = (IWorkspaceEdit)FDS_MainFeatureDataset.Workspace;  
  23.               Temp_WorkspaceEdit.StartEditing(true);  
  24.               Temp_WorkspaceEdit.StartEditOperation();  
  25.               IFeatureBuffer Temp_FeatureBuffer = Temp_TargetFeatureClass.CreateFeatureBuffer();  
  26.               //在目标要素类中插入所有错误要素  
  27.               IFeatureCursor featureCursor = Temp_TargetFeatureClass.Insert(true); ;  
  28.               while (Temp_ErrorFeature != null)  
  29.               {  
  30.                   IFeature Temp_Feature = Temp_ErrorFeature as IFeature;  
  31.                   //给目标要素附属性  
  32.                   Temp_FeatureBuffer.set_Value(1, Temp_ErrorFeature.OriginClassID);  
  33.                   Temp_FeatureBuffer.set_Value(2, Temp_ErrorFeature.OriginOID);  
  34.                   Temp_FeatureBuffer.set_Value(5, Temp_ErrorFeature.TopologyRuleType);  
  35.                   Temp_FeatureBuffer.Shape = Temp_Feature.Shape;  
  36.                   object featureOID = featureCursor.InsertFeature(Temp_FeatureBuffer);  
  37.                   featureCursor.Flush();//保存要素  
  38.                   Temp_ErrorFeature = Temp_EnumErrorFeature.Next();  
  39.               }  
  40.               Temp_WorkspaceEdit.StopEditOperation();  
  41.               Temp_WorkspaceEdit.StopEditing(true);  
  42.               System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);  
  43.           }  
  44.       }  

其中:

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

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

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


输出shape文件


[csharp]  view plain  copy
 
  1. private void PRV_OutPutToShape()  
  2. {  
  3.     FeatureClassToShapefile GP_FeatureClassToShape = new FeatureClassToShapefile();  
  4.     foreach (IFeatureClass Each_FeatureClass in LI_TopoErrorFeatureClass)  
  5.     {  
  6.         GP_FeatureClassToShape.Input_Features = Each_FeatureClass;  
  7.         GP_FeatureClassToShape.Output_Folder = "E:\\";  
  8.         GP_Tool.Execute(GP_FeatureClassToShape,null);  
  9.     }  
  10.               
  11. }  

你可能感兴趣的:(ArcEngine)