Creating feature classes (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with feature data > Creating and modifying schema > Creating feature classes (ArcObjects .NET 10.6 SDK)

Creating feature classes


Summary
This topic discusses how to create feature classes (both stand-alone and inside of feature datasets).

In this topic


About creating feature classes

Feature classes can exist as stand-alone entities at the workspace level of a geodatabase or within a feature dataset. The decision to create a feature class in a feature dataset or as a stand-alone feature class depends on the purpose of the feature class. Collections of spatially related feature classes are often grouped together in a feature dataset. If a topology is used to manage how features share geometry, a geometric network is built for a utility layer, a network dataset is built for routing and optimization, or a terrain is created. Feature classes must be created in a feature dataset.

Creating a stand-alone feature class

The IFeatureWorkspace.CreateFeatureClass method can be used to create a stand-alone feature class that is not part of a feature dataset. See the following code example:
[C#]
public IFeatureClass CreateStandaloneFeatureClass(IWorkspace workspace, String
    featureClassName, IFields fieldsCollection, String shapeFieldName)
{
    IFeatureWorkspace featureWorkspace=(IFeatureWorkspace)workspace;
    IFeatureClassDescription fcDesc=new FeatureClassDescriptionClass();
    IObjectClassDescription ocDesc=(IObjectClassDescription)fcDesc;

    // Use IFieldChecker to create a validated fields collection.
    IFieldChecker fieldChecker=new FieldCheckerClass();
    IEnumFieldError enumFieldError=null;
    IFields validatedFields=null;
    fieldChecker.ValidateWorkspace=workspace;
    fieldChecker.Validate(fieldsCollection, out enumFieldError, out validatedFields);

    // The enumFieldError enumerator can be inspected at this point to determine 
    // which fields were modified during validation.
    IFeatureClass featureClass=featureWorkspace.CreateFeatureClass
        (featureClassName, validatedFields, ocDesc.InstanceCLSID,
        ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, shapeFieldName, "")
        ;
    return featureClass;
}
[VB.NET]
Public Function CreateStandaloneFeatureClass(ByVal workspace As IWorkspace, ByVal featureClassName As String, ByVal fieldsCollection As IFields, ByVal shapeFieldName As String) As IFeatureClass
    Dim featureWorkspace As IFeatureWorkspace=CType(workspace, IFeatureWorkspace)
    Dim fcDesc As IFeatureClassDescription=New FeatureClassDescriptionClass()
    Dim ocDesc As IObjectClassDescription=CType(fcDesc, IObjectClassDescription)
    
    ' Use IFieldChecker to create a validated fields collection.
    Dim fieldChecker As IFieldChecker=New FieldCheckerClass()
    Dim enumFieldError As IEnumFieldError=Nothing
    Dim validatedFields As IFields=Nothing
    fieldChecker.ValidateWorkspace=workspace
    fieldChecker.Validate(fieldsCollection, enumFieldError, validatedFields)
    
    ' The enumFieldError enumerator can be inspected at this point to determine
    ' which fields were modified during validation.
    Dim featureClass As IFeatureClass=featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, shapeFieldName, "")
    Return featureClass
End Function
How to obtain correct parameter values for IFeatureWorkspace.CreateFeatureClass is explained in the CreateFeatureClass parameters section in this topic.
For more information on how to connect to a workspace, see Connecting to geodatabases and databases. For more information on how to create a geodatabase, see Creating geodatabases.
While similar to the IFeatureWorkspace.CreateTable method, CreateFeatureClass has the following additional parameters:
  • FeatureType parameter that specifies the category of features to be stored in this feature class (such as esriFTSimple, esriFTComplexEdgeFeature, and so on)
  • ShapeFieldName corresponding to the name of shape field (shapeFieldName identifies the field name of type Geometry in the input fields collection that represents the shape field for the feature class)

Creating a feature class in a feature dataset

Feature classes with a spatial relationship are generally grouped together in a feature dataset. Storing feature classes in a feature dataset allows them to participate in a topology to manage their shared geometry, a network to control their connectivity and perform network analysis, or a terrain so they can be used for surface generation and analysis.
Use the IFeatureDataset.CreateFeatureClass method to create feature classes in feature datasets. The arguments to this method are almost identical to IFeatureWorkspace.CreateFeatureClass, except the IFeatureDataset method requires the spatial reference of the feature class match of the containing feature dataset. See the following code example:
[C#]
public IFeatureClass CreateFeatureDatasetFeatureClass(IFeatureDataset featureDataset,
    String featureClassName, IFields fieldsCollection, String shapeFieldName)
{
    IFeatureClassDescription fcDesc=new FeatureClassDescriptionClass();
    IObjectClassDescription ocDesc=(IObjectClassDescription)fcDesc;

    // Use IFieldChecker to create a validated fields collection.
    IFieldChecker fieldChecker=new FieldCheckerClass();
    IEnumFieldError enumFieldError=null;
    IFields validatedFields=null;
    fieldChecker.ValidateWorkspace=featureDataset.Workspace;
    fieldChecker.Validate(fieldsCollection, out enumFieldError, out validatedFields);

    // The enumFieldError enumerator can be inspected at this point to determine 
    // which fields were modified during validation.
    IFeatureClass featureClass=featureDataset.CreateFeatureClass(featureClassName,
        validatedFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
        esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
    return featureClass;
}
[VB.NET]
Public Function CreateFeatureDatasetFeatureClass(ByVal featureDataset As IFeatureDataset, ByVal featureClassName As String, ByVal fieldsCollection As IFields, ByVal shapeFieldName As String) As IFeatureClass
    Dim fcDesc As IFeatureClassDescription=New FeatureClassDescriptionClass()
    Dim ocDesc As IObjectClassDescription=CType(fcDesc, IObjectClassDescription)
    
    ' Use IFieldChecker to create a validated fields collection.
    Dim fieldChecker As IFieldChecker=New FieldCheckerClass()
    Dim enumFieldError As IEnumFieldError=Nothing
    Dim validatedFields As IFields=Nothing
    fieldChecker.ValidateWorkspace=featureDataset.Workspace
    fieldChecker.Validate(fieldsCollection, enumFieldError, validatedFields)
    
    ' The enumFieldError enumerator can be inspected at this point to determine
    ' which fields were modified during validation.
    Dim featureClass As IFeatureClass=featureDataset.CreateFeatureClass(featureClassName, validatedFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "")
    Return featureClass
End Function
How to obtain correct parameter values for IFeatureWorkspace.CreateFeatureClass is explained in the CreateFeatureClass Parameters section in this topic.
For more information on how to create a new feature dataset, see Creating feature datasets.

Using IFieldChecker for field validation

Attempting to create a feature class with invalid field names result in an error being raised when the IFeatureWorkspace.CreateFeatureClass or IFeatureDataset.CreateFeatureClass methods are called. The IFieldChecker interface provides data source-specific validation for fields collections. The IFieldChecker.Validate method takes a collection of fields as an input parameter and returns a field error enumerator and a validated fields collection as output parameters. Before calling Validate, the ValidateWorkspace property must be set to the workspace where the fields will be created.
The following are the four types of field name errors:
  • Field shares its name with a word reserved by the data source (for example, Table)
  • Field shares its name with a previously defined field
  • Field contains an invalid character
  • Field name exceeds the data source's maximum length for field names
Most of the examples in this topic show how to use the IFieldChecker interface when creating a feature class. For more information, see the IFieldChecker, IEnumFieldError, and IFieldError interfaces.

CreateFeatureClass parameters

The following subsections describe setting the properties of a new feature class with the parameters of the CreateFeatureClass method. For more information about the properties of a feature class, see the following ArcGIS Help topics:

Feature class name

A feature class name identifies the feature class in the geodatabase. Make sure the name of the feature class is unique before calling CreateFeatureClass. This can be done by using the IWorkspace2.NameExists property (for geodatabase data sources only).
To verify that a name is appropriate for a specific workspace (as different data sources have different restrictions on names), use the IFieldChecker.ValidateTableName method. This method does not check if a dataset of the same name already exists, only whether the name is a reserved word, if it contains an invalid character, or if it has an invalid starting character. Some naming conventions are not allowed in any geodatabase—for example, using a number as the first character of a dataset name—while others are restricted due to the underlying database management system (DBMS).

Feature class fields

Each feature class has a collection of fields, which are the components that provide structure for the feature class. Each feature class must have at least two fields—ObjectID and Shape. The IFields, IField, and IFieldEdit interfaces can be used to create and populate the set of fields for a feature class, and the RequiredFields property of the IObjectClassDescription interface can be used to obtain a collection of predefined required fields.
For feature classes, RequiredFields returns a field collection containing the ObjectID field and a Shape field with a geometry type of polygon. To add more fields to a new or existing feature class, see Creating fields.
When creating a feature class with the same fields as an existing feature class, do not pass the Fields object from the existing class into the CreateFeatureClass method. Rather, cast the object to the IClone interface, clone it, and pass the resulting Fields object into the CreateFeatureClass method.
Set up the GeometryDef property of the Shape field with a GeometryDef object (using the IGeometryDef interface) containing the spatial and geometry information for the feature class. This information includes the following:
  • Geometry type
  • Spatial index information
  • Whether the feature class is m-aware or z-aware
  • Spatial reference information
Feature classes created in a feature dataset inherit the spatial reference of the containing feature dataset. Therefore, the spatial reference does not need to be specified in the GeometryDef object. If the fields collection is obtained from the RequiredFields property, GeometryDef information can be modified.
When creating stand-alone feature classes, the GeometryDef object must be fully set up with information on the spatial reference (the projected or geographic coordinate system plus the vertical coordinate system if needed, the coordinate domain, and the coordinate resolution). For more information on how to create a predefined spatial reference object, see Using the SpatialReferenceEnvironment.  
There is a vast array of predefined spatial reference systems. Many are based on information from the European Petroleum Survey Group (EPSG) Geodetic Parameter Dataset, which is becoming an industry standard. The EPSG Geodetic Parameter Dataset is maintained by the geodesy subcommittee of the International Oil & Gas Producers (OGP) Surveying & Positioning committee. For more information, see http://www.epsg.org.
If different releases of the geodatabase are used, see Constructing a high- or low-precision spatial reference, which discusses how to create spatial references in ArcGIS 9.2 and later geodatabases as well as in pre-9.2 geodatabases.
If a coordinate system with custom properties is needed, see Creating a custom geographic coordinate system and Creating a custom projected coordinate system.

CLSID and EXTCLSID

The class identifier (CLSID) parameter is used to specify the globally unique identifier (GUID) to instantiate the object representing a feature in that feature class. If null or nothing is passed in for the CLSID, the geodatabase assigns it the CLSID of esriGeodatabase.Feature, which in most cases is acceptable. If the feature class is being created to store objects other than instances of Feature, the instance class's GUID can be passed in at creation time or methods from the IClassSchemaEdit interface can be called to provide it later.
The extension class identifier (EXTCLSID) parameter specifies the GUID to use to instantiate the object and class extension behavior for the feature class extension (IFeatureClassExtension). This object must at least support the IClassExtension interface. If a null value is provided for the EXTCLSID, the new feature class will not have an extension.
Since class extensions are not required, a null value is acceptable for this parameter unless a class extension is explicitly needed (for example, when creating a dimension feature class). Class extensions can also be applied after a feature class has been created by using the IClassSchemaEdit interface.

Feature type

The feature type parameter specifies the category type of features stored in the feature class. In most cases, use the esriFTSimple value of the esriFeatureType enumeration—esriFTSimple specifies that the class contains simple features, such as points, polylines, and polygons.
Do not create classes that contain feature types other than simple features (esriFTSimple) or dimension features (esriFTDimension) with the IFeatureWorkspace.CreateFeatureClass and IFeatureDataset.CreateFeatureClass methods. For example, create annotation classes using the IAnnotationLayerFactory interface, and create raster catalogs using the IRasterWorkspaceEx interface.

Shape field name

The Shape field name identifies the name of the field of type Geometry in the fields collection that represents the Shape field of the feature class.

Configuration keyword

The optional configuration keyword parameter allows the application to control the physical layout for this table in the underlying relational database management system (RDBMS) or file geodatabase—for example, in an Oracle database, the configuration keyword controls the table space where the table is created, the initial and next extents, and other properties. 
The configuration keywords for an ArcSDE instance are set up by the ArcSDE data administrator. The list of available keywords supported by a workspace can be obtained using the IWorkspaceConfiguration interface.
The configuration keywords for a file geodatabase are predefined. In most cases, using a null value or an empty string for this parameter is acceptable.
For more information on configuration keywords, see What are configuration keywords?

Additional code examples

The following code example shows how to create a feature class using an instance of the FeatureClassDescription class, with an additional field added to the required fields collection.
[C#]
public IFeatureClass CreateFeatureClassWithFields(String featureClassName,
    IFeatureWorkspace featureWorkspace)
{
    // Instantiate a feature class description to get the required fields.
    IFeatureClassDescription fcDescription=new FeatureClassDescriptionClass();
    IObjectClassDescription ocDescription=(IObjectClassDescription)fcDescription;
    IFields fields=ocDescription.RequiredFields;
    IFieldsEdit fieldsEdit=(IFieldsEdit)fields;

    // Add a Name text field to the required fields.
    IField field=new FieldClass();
    IFieldEdit fieldEdit=(IFieldEdit)field;
    fieldEdit.Name_2="Name";
    fieldEdit.Type_2=esriFieldType.esriFieldTypeString;
    fieldsEdit.AddField(field);

    // Use IFieldChecker to create a validated fields collection.
    IFieldChecker fieldChecker=new FieldCheckerClass();
    IEnumFieldError enumFieldError=null;
    IFields validatedFields=null;
    fieldChecker.ValidateWorkspace=(IWorkspace)featureWorkspace;
    fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

    // The enumFieldError enumerator can be inspected at this point to determine 
    // which fields were modified during validation.

    // Create the feature class.
    IFeatureClass featureClass=featureWorkspace.CreateFeatureClass
        (featureClassName, validatedFields, ocDescription.InstanceCLSID,
        ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
        fcDescription.ShapeFieldName, "");
    return featureClass;
}
[VB.NET]
Public Function CreateFeatureClassWithFields(ByVal featureClassName As String, _
                                             ByVal featureWorkspace As IFeatureWorkspace) As IFeatureClass
    ' Instantiate a feature class description to get the required fields.
    Dim fcDescription As IFeatureClassDescription=New FeatureClassDescriptionClass()
    Dim ocDescription As IObjectClassDescription=CType(fcDescription, IObjectClassDescription)
    Dim fields As IFields=ocDescription.RequiredFields
    Dim fieldsEdit As IFieldsEdit=CType(fields, IFieldsEdit)
    
    ' Add a Name text field to the required fields.
    Dim field As IField=New FieldClass()
    Dim fieldEdit As IFieldEdit=CType(field, IFieldEdit)
    fieldEdit.Name_2="Name"
    fieldEdit.Type_2=esriFieldType.esriFieldTypeString
    fieldsEdit.AddField(field)
    
    ' Use IFieldChecker to create a validated fields collection.
    Dim fieldChecker As IFieldChecker=New FieldCheckerClass()
    Dim enumFieldError As IEnumFieldError=Nothing
    Dim validatedFields As IFields=Nothing
    fieldChecker.ValidateWorkspace=CType(featureWorkspace, IWorkspace)
    fieldChecker.Validate(fields, enumFieldError, validatedFields)
    
    ' The enumFieldError enumerator can be inspected at this point to determine
    ' which fields were modified during validation.
    
    ' Create the feature class.
    Dim featureClass As IFeatureClass=featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, _
                                        ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, _
                                        fcDescription.ShapeFieldName, "")
    Return featureClass
End Function
The following code example shows how to generate a feature class using a feature class description, but rather than using the default GeometryDef associated with the Shape field, it modifies the GeometryDef to apply a spatial reference as well as a new geometry type (esriGeometryType.esriGeometryPoint). By default, a feature class has an unknown coordinate system and polygonal geometry.
[C#]
public IFeatureClass CreateFeatureClassWithSR(String featureClassName,
    IFeatureWorkspace featureWorkspace, ISpatialReference spatialReference)
{
    // Instantiate a feature class description to get the required fields.
    IFeatureClassDescription fcDescription=new FeatureClassDescriptionClass();
    IObjectClassDescription ocDescription=(IObjectClassDescription)fcDescription;
    IFields fields=ocDescription.RequiredFields;

    // Find the shape field in the required fields and modify its GeometryDef to
    // use point geometry and to set the spatial reference.
    int shapeFieldIndex=fields.FindField(fcDescription.ShapeFieldName);
    IField field=fields.get_Field(shapeFieldIndex);
    IGeometryDef geometryDef=field.GeometryDef;
    IGeometryDefEdit geometryDefEdit=(IGeometryDefEdit)geometryDef;
    geometryDefEdit.GeometryType_2=esriGeometryType.esriGeometryPoint;
    geometryDefEdit.SpatialReference_2=spatialReference;

    // In this example, only the required fields from the class description are used as fields
    // for the feature class. If additional fields are added, use IFieldChecker to
    // validate them.

    // Create the feature class.
    IFeatureClass featureClass=featureWorkspace.CreateFeatureClass
        (featureClassName, fields, ocDescription.InstanceCLSID,
        ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
        fcDescription.ShapeFieldName, "");
    return featureClass;
}
[VB.NET]
Public Function CreateFeatureClassWithSR(ByVal featureClassName As String, _
                                         ByVal featureWorkspace As IFeatureWorkspace, ByVal spatialReference As ISpatialReference) As IFeatureClass
    ' Instantiate a feature class description to get the required fields.
    Dim fcDescription As IFeatureClassDescription=New FeatureClassDescriptionClass()
    Dim ocDescription As IObjectClassDescription=CType(fcDescription, IObjectClassDescription)
    Dim fields As IFields=ocDescription.RequiredFields
    
    ' Find the shape field in the required fields and modify its GeometryDef to
    ' use point geometry and to set the spatial reference.
    Dim shapeFieldIndex As Integer=fields.FindField(fcDescription.ShapeFieldName)
    Dim field As IField=fields.Field(shapeFieldIndex)
    Dim geometryDef As IGeometryDef=field.GeometryDef
    Dim geometryDefEdit As IGeometryDefEdit=CType(geometryDef, IGeometryDefEdit)
    geometryDefEdit.GeometryType_2=esriGeometryType.esriGeometryPoint
    geometryDefEdit.SpatialReference_2=spatialReference
    
    ' In this example, only the required fields from the class description are used as fields
    ' for the feature class. If additional fields are added, use IFieldChecker to
    ' validate them.
    
    ' Create the feature class.
    Dim featureClass As IFeatureClass=featureWorkspace.CreateFeatureClass(featureClassName, fields, _
                                        ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, _
                                        fcDescription.ShapeFieldName, "")
    Return featureClass
End Function
The following code example shows how to create a feature class without using the FeatureClassDescription class. A feature class must contain ObjectID and Shape fields, but their names need not be OBJECTID and Shape (the default names). The classExtensionUID parameter allows a class extension to be set using the method. Passing null (in C#) or Nothing (in VB .NET) indicates no class extension should be used.
[C#]
public IFeatureClass CreateWithoutDescription(String featureClassName, UID
    classExtensionUID, IFeatureWorkspace featureWorkspace)
{
    // Create a fields collection for the feature class.
    IFields fields=new FieldsClass();
    IFieldsEdit fieldsEdit=(IFieldsEdit)fields;

    // Add an ObjectID field to the fields collection. This is mandatory for feature classes.
    IField oidField=new FieldClass();
    IFieldEdit oidFieldEdit=(IFieldEdit)oidField;
    oidFieldEdit.Name_2="OID";
    oidFieldEdit.Type_2=esriFieldType.esriFieldTypeOID;
    fieldsEdit.AddField(oidField);

    // Create a geometry definition (and spatial reference) for the feature class.
    IGeometryDef geometryDef=new GeometryDefClass();
    IGeometryDefEdit geometryDefEdit=(IGeometryDefEdit)geometryDef;
    geometryDefEdit.GeometryType_2=esriGeometryType.esriGeometryPoint;
    ISpatialReferenceFactory spatialReferenceFactory=new
        SpatialReferenceEnvironmentClass();
    ISpatialReference spatialReference =
        spatialReferenceFactory.CreateProjectedCoordinateSystem((int)
        esriSRProjCSType.esriSRProjCS_NAD1983UTM_20N);
    ISpatialReferenceResolution spatialReferenceResolution=
        (ISpatialReferenceResolution)spatialReference;
    spatialReferenceResolution.ConstructFromHorizon();
    spatialReferenceResolution.SetDefaultXYResolution();
    ISpatialReferenceTolerance spatialReferenceTolerance=
        (ISpatialReferenceTolerance)spatialReference;
    spatialReferenceTolerance.SetDefaultXYTolerance();
    geometryDefEdit.SpatialReference_2=spatialReference;

    // Add a geometry field to the fields collection. This is where the geometry definition is applied.
    IField geometryField=new FieldClass();
    IFieldEdit geometryFieldEdit=(IFieldEdit)geometryField;
    geometryFieldEdit.Name_2="Shape";
    geometryFieldEdit.Type_2=esriFieldType.esriFieldTypeGeometry;
    geometryFieldEdit.GeometryDef_2=geometryDef;
    fieldsEdit.AddField(geometryField);

    // Create a Name text field for the fields collection.
    IField nameField=new FieldClass();
    IFieldEdit nameFieldEdit=(IFieldEdit)nameField;
    nameFieldEdit.Name_2="Name";
    nameFieldEdit.Type_2=esriFieldType.esriFieldTypeString;
    nameFieldEdit.Length_2=20;
    fieldsEdit.AddField(nameField);

    // Use IFieldChecker to create a validated fields collection.
    IFieldChecker fieldChecker=new FieldCheckerClass();
    IEnumFieldError enumFieldError=null;
    IFields validatedFields=null;
    fieldChecker.ValidateWorkspace=(IWorkspace)featureWorkspace;
    fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

    // The enumFieldError enumerator can be inspected at this point to determine 
    // which fields were modified during validation.

    // Create the feature class. Note that the CLSID parameter is null—this indicates to use the
    // default CLSID, esriGeodatabase.Feature (acceptable in most cases for feature classes).
    IFeatureClass featureClass=featureWorkspace.CreateFeatureClass
        (featureClassName, validatedFields, null, classExtensionUID,
        esriFeatureType.esriFTSimple, "Shape", "");
    return featureClass;
}
[VB.NET]
Public Function CreateWithoutDescription(ByVal featureClassName As String, ByVal classExtensionUID As UID, _
                                         ByVal featureWorkspace As IFeatureWorkspace) As IFeatureClass
    ' Create a fields collection for the feature class.
    Dim fields As IFields=New FieldsClass()
    Dim fieldsEdit As IFieldsEdit=CType(fields, IFieldsEdit)
    
    ' Add an ObjectID field to the fields collection. This is mandatory for feature classes.
    Dim oidField As IField=New FieldClass()
    Dim oidFieldEdit As IFieldEdit=CType(oidField, IFieldEdit)
    oidFieldEdit.Name_2="OID"
    oidFieldEdit.Type_2=esriFieldType.esriFieldTypeOID
    fieldsEdit.AddField(oidField)
    
    ' Create a geometry definition (and spatial reference) for the feature class.
    Dim geometryDef As IGeometryDef=New GeometryDefClass()
    Dim geometryDefEdit As IGeometryDefEdit=CType(geometryDef, IGeometryDefEdit)
    geometryDefEdit.GeometryType_2=esriGeometryType.esriGeometryPoint
    Dim spatialReferenceFactory As ISpatialReferenceFactory=New SpatialReferenceEnvironmentClass()
    Dim spatialReference As ISpatialReference=_
                                                spatialReferenceFactory.CreateProjectedCoordinateSystem(CType(esriSRProjCSType.esriSRProjCS_NAD1983UTM_20N, Integer))
    Dim spatialReferenceResolution As ISpatialReferenceResolution=CType(spatialReference, ISpatialReferenceResolution)
    spatialReferenceResolution.ConstructFromHorizon()
    spatialReferenceResolution.SetDefaultXYResolution()
    Dim spatialReferenceTolerance As ISpatialReferenceTolerance=CType(spatialReference, ISpatialReferenceTolerance)
    spatialReferenceTolerance.SetDefaultXYTolerance()
    geometryDefEdit.SpatialReference_2=spatialReference
    
    ' Add a geometry field to the fields collection. This is where the geometry definition is applied.
    Dim geometryField As IField=New FieldClass()
    Dim geometryFieldEdit As IFieldEdit=CType(geometryField, IFieldEdit)
    geometryFieldEdit.Name_2="Shape"
    geometryFieldEdit.Type_2=esriFieldType.esriFieldTypeGeometry
    geometryFieldEdit.GeometryDef_2=geometryDef
    fieldsEdit.AddField(geometryField)
    
    ' Create a Name text field for the fields collection.
    Dim nameField As IField=New FieldClass()
    Dim nameFieldEdit As IFieldEdit=CType(nameField, IFieldEdit)
    nameFieldEdit.Name_2="Name"
    nameFieldEdit.Type_2=esriFieldType.esriFieldTypeString
    nameFieldEdit.Length_2=20
    fieldsEdit.AddField(nameField)
    
    ' Use IFieldChecker to create a validated fields collection.
    Dim fieldChecker As IFieldChecker=New FieldCheckerClass()
    Dim enumFieldError As IEnumFieldError=Nothing
    Dim validatedFields As IFields=Nothing
    fieldChecker.ValidateWorkspace=CType(featureWorkspace, IWorkspace)
    fieldChecker.Validate(fields, enumFieldError, validatedFields)
    
    ' The enumFieldError enumerator can be inspected at this point to determine
    ' which fields were modified during validation.
    
    ' Create the feature class. Note that the CLSID parameter is null—this indicates to use the
    ' default CLSID, esriGeodatabase.Feature (acceptable in most cases for feature classes).
    Dim featureClass As IFeatureClass=featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, _
                                        Nothing, classExtensionUID, esriFeatureType.esriFTSimple, "Shape", "")
    Return featureClass
End Function


See Also:

Creating tables
Creating fields
Creating feature datasets




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine: Geodatabase Update