Geoprocessor - C# - Create empty feature class using template for attribute fields

Discussion created by blm43 on Jun 17, 2014
Latest reply on Jun 17, 2014 by blm43

I am using the ArcObjects SDK - C# and geoprocessor to create an empty polyline featureclass in a file geodatabase. This feature class will use an existing feature class in the file geodatabase as a template for its' fields.

I can get this to work ok using Python, however when I run my C#/ArcObjects code the required fields are not being created from the template. The output created only has the default featureclass attributes - OBJECTID, Shape and Shape_Length.

Can anyone point out where I am going wrong? I think I have used the correct syntax ok from ArcGIS Geoprocessing help. The code is shown below. Any help would be much appreciated to solve a frustrating problem!

Kind Regards

Barry Mason
Senior DBA/GIS Developer


Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                            IWorkspace out_path = workspaceFactory.OpenFromFile(@"C:\ProfLP.gdb", 0);

IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)out_path;

string out_name = "outputTest";
string geometry_type = "POLYLINE";
IFeatureLayer pInFeatLayer = new FeatureLayerClass();
IFeatureClass pInFeatClass = featureWorkspace.OpenFeatureClass("Profile42770");
pInFeatLayer.Name = pInFeatClass.AliasName;
pInFeatLayer.FeatureClass = pInFeatClass;

string has_m = "DISABLED";
string has_z = "DISABLED";

SpatialReferenceEnvironment spatialRefEnv = new SpatialReferenceEnvironmentClass();
ISpatialReference spatial_reference = (ISpatialReference)spatialRefEnv.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_BritishNationalGrid); //OSGB

string config_keyword = "";
Double spatial_grid_1 = 0;
Double spatial_grid_2 = 0;
Double spatial_grid_3 = 0;

// Create the geoprocessor.
IGeoProcessor2 gp = new GeoProcessorClass();

// Create an IVariantArray to hold the parameter values.
IVariantArray parameters = new VarArrayClass();

// Populate the variant array with parameter values.

object sev = null;

// Execute the tool.
gp.Execute("CreateFeatureclass_management", parameters, null);
Console.WriteLine(gp.GetMessages(ref sev));


The console output is:

CreateFeatureclass C:\ProfLP.gdb outputTest POLYLINE Profile42770 DISABLED
DISABLED "PROJCS['British_National_Grid',GEOGCS['GCS_OSGB_1936',DATUM['D_O
_Origin',49.0],UNIT['Meter',1.0]];-5220400 -15524400 10000;-100000 10000;-100000
10000;0.001;0.001;0.001;IsHighPrecision" # 0 0 0
Start Time: Tue Jun 17 11:02:40 2014
Succeeded at Tue Jun 17 11:02:40 2014 (Elapsed Time: 0.00 seconds)