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

4074
3
06-17-2014 02:06 AM
BarryMason
New Contributor
Hello,

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
SPT



/////////////////////////////////////////////////////////////////////////////////////////

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.
parameters.Add(out_path);
parameters.Add(out_name);
parameters.Add(geometry_type);
parameters.Add(pInFeatLayer);
parameters.Add(has_m);
parameters.Add(has_z);
parameters.Add(spatial_reference);
//parameters.Add(config_keyword);
//parameters.Add(spatial_grid_1);
//parameters.Add(spatial_grid_2);
//parameters.Add(spatial_grid_3);

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
SGB_1936',SPHEROID['Airy_1830',6377563.396,299.3249646]],PRIMEM['Greenwich',0.0]
,UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER[
'False_Easting',400000.0],PARAMETER['False_Northing',-100000.0],PARAMETER['Centr
al_Meridian',-2.0],PARAMETER['Scale_Factor',0.9996012717],PARAMETER['Latitude_Of
_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)
0 Kudos
3 Replies
ModyBuchbinder
Esri Regular Contributor
Hi

Try to give the FeatureClass as the argument and not the FeatureLayer.
Translate the template layer into a string (full path) will always work.
Other then that there is better way to run GP tools in C# by using the real parameter names. Check this: http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/0001/000100000161000000.htm

Have fun
Mody
0 Kudos
AhmedEl-Sisi
Occasional Contributor III
As Mody said you can pass your template layer as string because it's a Multi value parameter.
You can also use ESRI.ArcGIS.DataManagementTools.CreateFeatureclass which is the same.

Another approach is to use IfeatureWorkspace.CreateFeatureClass and pass your fields from Template featureclass.

Regards,
0 Kudos
BarryMason
New Contributor
Many thanks guys. Passing the template argument in as a string solved the problem. It was confusing because the geoprocessing help said that this argument was a feature layer.

Thanks again

Barry
0 Kudos