Hi new ForumI am writing a Class Extension in C# for a Line Feature Class with z-values.I have constructed the following piece of code from various VB-examples. It will make a featureclass, but it seems that the geometry definitions in my code will not override the settings in the New Feature Class dialog box in Arc Catalog.Can I somehow make sure that this feature class will always be a line class?Another question:This featureclass will normally reside in a dataset with defined spatial reference.I have to define a spatial reference anyway, in order to make a Geometry Definition, if I understand it right?Thanks in advance for any input.
IFields IObjectClassDescription.RequiredFields
{
get
{
// Get the feature class required fields.
IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;
IFields requiredFields = ocDescription.RequiredFields;
IFieldsEdit requiredFieldsEdit = (IFieldsEdit)requiredFields;
try
{
//Add objectID Field
IField oidField = new FieldClass();
IFieldEdit oidFieldEdit = (IFieldEdit)oidField;
oidFieldEdit.Name_2 = "OBJECTID";
oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
requiredFieldsEdit.set_Field(0, oidField);
// Get a spatial reference
SpatialReferenceEnvironment spatialReferenceEnvironment = new SpatialReferenceEnvironmentClass();
ISpatialReferenceFactory spatialReferenceFactory = (ISpatialReferenceFactory)spatialReferenceEnvironment;
ISpatialReference pSR = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile
("Path to Projection File......");
// Get a Geometry definition
IGeometryDef pGeomDef = new GeometryDefClass();
IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;
pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
pGeomDefEdit.AvgNumPoints_2 = 2;
pGeomDefEdit.HasZ_2 = true;
pGeomDefEdit.SpatialReference_2 = pSR;
// Add the shape field
IField shapeField = new FieldClass();
IFieldEdit shapeFieldEdit = (IFieldEdit)shapeField;
shapeFieldEdit.Name_2 = "MYSHAPE";
shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
shapeFieldEdit.GeometryDef_2 = pGeomDef;
shapeFieldEdit.IsNullable_2 = true;
shapeFieldEdit.Required_2 = true;
requiredFieldsEdit.set_Field(1, shapeField);
// Add a symbol field, required for subtypes
IField symbolField = new FieldClass();
IFieldEdit symbolFieldEdit = (IFieldEdit)symbolField;
symbolFieldEdit.Name_2 = "GM_SYMBOL";
symbolFieldEdit.Required_2 = true;
symbolFieldEdit.IsNullable_2 = false;
symbolFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
requiredFieldsEdit.AddField(symbolField);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return requiredFields;
}
}