KevinGebhardt86

Error Exporting IFeatureClass to Geodatabase

Discussion created by KevinGebhardt86 on Oct 30, 2012
Latest reply on Oct 31, 2012 by KevinGebhardt86
Hello,
I'm trying to export an IFeatureClass to Geodatabase but i get the following error message:
[ATTACH=CONFIG]18837[/ATTACH]
Here is my code:
private void saveToFile(IFeatureClass featureClass, String outputPath)
        {
            FileGDBWorkspaceFactory pWorkspaceFactory = default(FileGDBWorkspaceFactory);
            IWorkspace pWorkspace = default(IWorkspace);
            pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory();
            pWorkspace = pWorkspaceFactory.OpenFromFile(outputPath, 0);
            IGeographicCoordinateSystem pGCS = default(IGeographicCoordinateSystem);
            SpatialReferenceEnvironment pSpatialReferenceEnv = default(SpatialReferenceEnvironment);
            ISpatialReference2 pSpatialReference = default(ISpatialReference2);
            IProjectedCoordinateSystem PJCS = default(IProjectedCoordinateSystem);
            pSpatialReferenceEnv = new SpatialReferenceEnvironment();
            PJCS = pSpatialReferenceEnv.CreateProjectedCoordinateSystem(Convert.ToInt32(esriSRProjCS4Type.esriSRProjCS_DHDN_3_Degree_Gauss_Zone_4));
           
            pSpatialReference = (ISpatialReference2)PJCS;
           
            IGeometryDef pGeometryDef = default(IGeometryDef);
            IGeometryDefEdit pGeometryDefEdit = default(IGeometryDefEdit);
            pGeometryDef = new GeometryDef();
           
            pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;
            pGeometryDefEdit.GeometryType_2 = featureClass.ShapeType;
            pGeometryDefEdit.SpatialReference_2 = pSpatialReference;

            ExportFeatureClass("test2", featureClass, pWorkspace, pSpatialReference, pGeometryDef);
            
        }
        public void ExportFeatureClass(string strLayerName, IFeatureClass pFeatureClass, IWorkspace pOutWorkspace, ISpatialReference pSpatialReference, IGeometryDef pGeometryDef)
        {
            IFeatureClassName pInFeatureClassName = default(IFeatureClassName);
            IDataset pDataset = default(IDataset);
            IWorkspaceName pOutWorkspaceName = default(IWorkspaceName);
            IFeatureClassName pOutFeatureClassName = default(IFeatureClassName);
            IDatasetName pDatasetName = default(IDatasetName);
            IExportOperation pExportOperation = default(IExportOperation);
            IWorkspace pInWorkspace = default(IWorkspace);

            pDataset = (IDataset)pFeatureClass;
            pInFeatureClassName = (IFeatureClassName)pDataset.FullName;
            pInWorkspace = pDataset.Workspace;
            pDataset = (IDataset)pOutWorkspace;
            pOutWorkspaceName = (IWorkspaceName)pDataset.FullName;

            pOutFeatureClassName = new FeatureClassNameClass();
            pDatasetName = (IDatasetName)pOutFeatureClassName;
            pDatasetName.Name = strLayerName;
            pDatasetName.WorkspaceName = pOutWorkspaceName;

            var queryFilter = new QueryFilterClass();
            queryFilter.SubFields = "*";
            queryFilter.WhereClause = "";

            pExportOperation = new ExportOperation();
          
            pExportOperation.ExportFeatureClass((IDatasetName)pInFeatureClassName, queryFilter, null, pGeometryDef, pOutFeatureClassName, 0);

            //Cleanup
            pInFeatureClassName = null;
            pDataset = null;
            pOutWorkspaceName = null;
            pOutFeatureClassName = null;
            pDatasetName = null;
            pExportOperation = null;
            pInWorkspace = null;
        }
Thanks

Attachments

Outcomes