Creating Blank Schema of Feature Class

2641
5
Jump to solution
09-18-2015 02:32 AM
Highlighted
Occasional Contributor

Hello All,

Anyone can please help mein exporting blank schema of feature class from database to local fgdb. And then adding it back to TOC. i am into 10.3. If possible using code of  gp or arctool box tool to achieve this will be very good performance wise

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor

Hello Everyone,

I have used  queryFilter.WhereClause = iPLANConstants.ATROBJECTID +"=0" code to control empty schema . thanks everyone for your great suggestion

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 = iPLANConstants.ATROBJECTID +"=0";

            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;

        }

View solution in original post

5 Replies
Highlighted
Occasional Contributor

I think this is what you are looking for Create Feature Class (Data Management)

And just in case you need how to run this tool in ArcObjects

ArcObjects Help for .NET developers - How to run a geoprocessing tool

For adding layer to map

ArcObjects Help for .NET developers - Add Layer File to ActiveView Snippet

But I think performance wise it will be better without gp tools but then you need to write more code:

So for that refer ArcObjects Help for .NET developers - Create FeatureClass Snippet

In this approach you open the database feature class read it's fields and then create your feature class in FGDB with similar schema.

HTH

Highlighted
Occasional Contributor

Hi Mahtab,

Thanks for your quick reply but this is what i am trying to do but i dont want features to get copied. I only want blank schema . can you please help me in same

Error Exporting IFeatureClass to Geodatabase

Regards

Reply
0 Kudos
Highlighted
Occasional Contributor

This one is different option for the purpose of exporting feature class. If you don't want to use the GP tool then you can use the create feature class option. For example

                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory"));

                IWorkspace workspace = workspaceFactory.OpenFromFile(@"C:\Temp\test.mdb", 0);

                IWorkspace2 workspace2 = workspace as IWorkspace2;

                IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;

                IFeatureClass sourceFc = featureWorkspace.OpenFeatureClass("MySourceFC");

                CreateFeatureClass(workspace2, null, "MyTargetFC", sourceFc.Fields, null, null, string.Empty);

Here I am using a PGDB but you can change it to whatever you need. CreateFeatureClass function is from the snippet that I shared earlier.

Thanks,

Mahtab

Reply
0 Kudos
Highlighted
Regular Contributor III

Use the "Export XML Workspace Document" GP tool and select 'SCHEMA_ONLY' in Export Options.

Then import this XML file into the desired geodatabase using the "Import XML Workspace Document" tool.

Reply
0 Kudos
Highlighted
Occasional Contributor

Hello Everyone,

I have used  queryFilter.WhereClause = iPLANConstants.ATROBJECTID +"=0" code to control empty schema . thanks everyone for your great suggestion

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 = iPLANConstants.ATROBJECTID +"=0";

            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;

        }

View solution in original post