1 public bool fc2fc(IFeatureClass pInFeatureClass, IWorkspace pOutWorkspace,string pOutDataSName, string poutFatureName, IQueryFilter queryFilter = null) 2 { 3 IDataset pIndataset = null; 4 IDataset pOutDataset = null; 5 try 6 { 7 if (pInFeatureClass == null || pOutWorkspace == null || string.IsNullOrEmpty(poutFatureName)) return false; 8 IFeatureClassName pInFeatureclassName; 9 pIndataset = (IDataset)pInFeatureClass; 10 pInFeatureclassName = (IFeatureClassName)pIndataset.FullName; 11 IFeatureClassName pOutFeatureClassName; 12 IDatasetName pOutDatasetName; 13 pOutDataset = (IDataset)pOutWorkspace; 14 pOutFeatureClassName = new FeatureClassNameClass(); 15 pOutDatasetName = (IDatasetName)pOutFeatureClassName; 16 pOutDatasetName.WorkspaceName = (IWorkspaceName)pOutDataset.FullName; 17 pOutDatasetName.Name = poutFatureName; 18 IFields pInFields, pOutFields; 19 IFieldChecker pFieldChecker = new FieldCheckerClass(); 20 IEnumFieldError pError; 21 pInFields = pInFeatureClass.Fields; 22 String pShapeFieldName = pInFeatureClass.ShapeFieldName; 23 int pFieldIndex = pInFeatureClass.FindField(pShapeFieldName); 24 IField pShapeField = pInFields.get_Field(pFieldIndex); 25 IGeometryDef pTargetGeometryDef = pShapeField.GeometryDef; 26 if (pTargetGeometryDef.HasZ || pTargetGeometryDef.HasM) 27 { 28 IGeometryDefEdit pGeoDefEdit = pTargetGeometryDef as IGeometryDefEdit; 29 pGeoDefEdit.HasZ_2 = false; 30 pGeoDefEdit.HasM_2 = false; 31 } 32 pFieldChecker.Validate(pInFields, out pError, out pOutFields); 33 Console.WriteLine(pError); 34 IEnumDatasetName pEnumDatasetName = (pOutWorkspace as IWorkspace).get_DatasetNames(esriDatasetType.esriDTFeatureDataset); 35 pEnumDatasetName.Reset(); 36 IDatasetName pDatasetName = pEnumDatasetName.Next(); 37 IFeatureDatasetName datasetName = null; 38 while (pDatasetName != null) 39 { 40 if (pDatasetName.Type == esriDatasetType.esriDTFeatureDataset) 41 { 42 if (pDatasetName.Name == pOutDataSName) 43 { 44 datasetName = pDatasetName as IFeatureDatasetName; 45 break; 46 } 47 } 48 } 49 50 51 IFeatureDataConverter one2another = new FeatureDataConverterClass(); 52 try 53 { 54 if (pOutWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) 55 { 56 one2another.ConvertFeatureClass(pInFeatureclassName, null, datasetName, pOutFeatureClassName, pTargetGeometryDef, 57 pOutFields, "", 1000, 0); 58 } 59 else 60 { 61 one2another.ConvertFeatureClass(pInFeatureclassName, queryFilter, datasetName, pOutFeatureClassName, pTargetGeometryDef, pOutFields, "", 1000, 0); 62 } 63 } 64 finally 65 { 66 if (one2another != null) 67 Marshal.ReleaseComObject(one2another); 68 } 69 return true; 70 } 71 catch (Exception ex) 72 { 73 LogAPI.Debug(ex); 74 try 75 { 76 InsertFeatureToFeature(pInFeatureClass, (pOutWorkspace as IFeatureWorkspace).OpenFeatureClass(poutFatureName), queryFilter); 77 } 78 catch (Exception ex2) 79 { 80 LogAPI.Debug(ex2); 81 } 82 return false; 83 } 84 finally 85 { 86 //if (pIndataset != null) 87 // Marshal.FinalReleaseComObject(pIndataset); 88 //if (pOutDataset != null) 89 // Marshal.FinalReleaseComObject(pOutDataset); 90 } 91 }