FeatureClass의 "import"(변환) 기능

12055 단어 import
 1 /// <summary>

 2         /// FeatureClass "import" .

 3         /// </summary>

 4         /// <param name="srcWorkspaceFactory"> IWorkspaceFactory2 </param>

 5         /// <param name="srcWorkspacePath"> , :"G:\doc\gis\1.400\data\pdb.mdb"</param>

 6         /// <param name="srcFeatureName"> , :"hyd1_4l_1"</param>

 7         /// <param name="desWorkspaceFactory"> IWorkspaceFactory2 </param>

 8         /// <param name="desWorkspacePath"> , :"G:\doc\gis\1.400\data\desPdb.mdb"( )</param>

 9         /// <param name="desFeatureName"> , :"desF"</param>

10         public static void ConvertFeatureClass(ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 srcWorkspaceFactory, string srcWorkspacePath, string srcFeatureName, ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 desWorkspaceFactory, string desWorkspacePath, string desFeatureName) {

11             // .

12             ESRI.ArcGIS.Geodatabase.IWorkspace srcWs = srcWorkspaceFactory.OpenFromFile(srcWorkspacePath, 0);

13             ESRI.ArcGIS.Geodatabase.IWorkspace desWs = desWorkspaceFactory.OpenFromFile(desWorkspacePath, 0);   // , open.

14 

15             // .

16             ESRI.ArcGIS.Geodatabase.IFeatureWorkspace srcFws = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)srcWs;

17             ESRI.ArcGIS.Geodatabase.IFeatureClass srcFc = srcFws.OpenFeatureClass(srcFeatureName);

18             ESRI.ArcGIS.Geodatabase.IDataset srcDs = (ESRI.ArcGIS.Geodatabase.IDataset)srcFc;

19             ESRI.ArcGIS.Geodatabase.IFeatureClassName srcFcName = (ESRI.ArcGIS.Geodatabase.IFeatureClassName)srcDs.FullName;

20 

21             // .

22             ESRI.ArcGIS.Geodatabase.IDataset desDs = (ESRI.ArcGIS.Geodatabase.IDataset)desWs;

23             ESRI.ArcGIS.esriSystem.IName desName = (ESRI.ArcGIS.esriSystem.IName)desDs.FullName;

24             ESRI.ArcGIS.Geodatabase.IWorkspaceName2 desWsName = (ESRI.ArcGIS.Geodatabase.IWorkspaceName2)desName;

25             ESRI.ArcGIS.Geodatabase.IFeatureClassName desFcName = new ESRI.ArcGIS.Geodatabase.FeatureClassNameClass();

26             ESRI.ArcGIS.Geodatabase.IDatasetName2 desDsName = (ESRI.ArcGIS.Geodatabase.IDatasetName2)desFcName;

27             desDsName.Name = desFeatureName;

28             desDsName.WorkspaceName = desWsName;

29 

30             // .

31             ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();

32             ESRI.ArcGIS.Geodatabase.IFields srcFields = srcFc.Fields;

33             ESRI.ArcGIS.Geodatabase.IFields desFields = null;

34             ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldErr = null;

35             fieldChecker.InputWorkspace = srcWs;

36             fieldChecker.ValidateWorkspace = desWs;

37             fieldChecker.Validate(srcFields, out enumFieldErr, out desFields);

38             if (enumFieldErr != null)

39                 System.Windows.Forms.MessageBox.Show("Errors were encountered during field validation");

40 

41             string shpFieldName = srcFc.ShapeFieldName;

42             int fieldIndex = srcFc.FindField(shpFieldName);

43             ESRI.ArcGIS.Geodatabase.IField shpField = srcFields.get_Field(fieldIndex);

44             ESRI.ArcGIS.Geodatabase.IGeometryDef DesGeoDef = shpField.GeometryDef;

45 

46             // .

47             ESRI.ArcGIS.Geodatabase.IFeatureDataConverter fdConverter = new ESRI.ArcGIS.Geodatabase.FeatureDataConverterClass();

48             ESRI.ArcGIS.Geodatabase.IEnumInvalidObject enuInvalidObj = fdConverter.ConvertFeatureClass(srcFcName, null, null, desFcName, DesGeoDef, desFields, "", 1000, 0);

49             enuInvalidObj.Reset();

50             ESRI.ArcGIS.Geodatabase.IInvalidObjectInfo inValidObjInfo = null;

51             while ((inValidObjInfo = enuInvalidObj.Next()) != null)

52                 System.Windows.Forms.MessageBox.Show(string.Format("Errors occurred for the following feature: {0}", inValidObjInfo.InvalidObjectID));

53         }

주 함수에서 호출하기
1 ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 srcWsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();

2 ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 desWsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();

3 

4 string srcWsPath = @"G:\doc\gis\1.400\data\pdb.mdb";

5 string desWsPath = @"G:\doc\gis\1.400\data\desPdb.mdb";

6 

7 string srcFcName = "hyd1_4l_1";

8 string desFcName = "desF";

9 Engine.App_Code.Feature_Assist.ConvertFeatureClass(srcWsf, srcWsPath, srcFcName, desWsf, desWsPath, desFcName);

좋은 웹페이지 즐겨찾기