Error Exporting IFeatureClass to Geodatabase

1719
2
10-30-2012 05:42 AM
Highlighted
New Contributor III
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
Reply
0 Kudos
2 Replies
Highlighted
Esri Notable Contributor
Hi,

Check out this help topic: Constructing a high- or low-precision spatial reference

Melita
Reply
0 Kudos
Highlighted
New Contributor III
Thanks, that solved my problem.
Reply
0 Kudos