In this topic
A feature class is a collection of geographic features that share the same geometry type (such as point, line, or polygon) and the same attribute fields for a common area. Streets, well points, parcels, soil types, and census tracts are examples of feature classes.
Feature classes with a spatial or thematic 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 that they can be used for surface generation and analysis.
Use the IFeatureDataset.CreateFeatureClass method to create new feature classes in feature datasets. The arguments to this method are almost identical to IFeatureWorkspace.CreateFeatureClass, except the IFeatureDataset method requires that the spatial reference of the feature class match that of the containing feature dataset.
The following discusses the other arguments to the CreateFeatureClass method:
The feature class name uniquely identifies it within the geodatabase. The specified name cannot contain spaces, punctuation, or start with a number. Ensure that the name of your feature class is unique; this can be done by using the IWorkspace2.NameExists property.
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 fields. While you can use the IFields, IField, and IFieldEdit interfaces to create and populate the set of fields for a feature class, you can also use the RequiredFields property on IObjectClassDescription interface 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 new or existing feature class, see the article on How to create new fields.
The GeometryDef property of the field object for the Shape field must be set up with a GeometryDef object containing the spatial and geometry information for the feature class. This information includes:
- The geometry type
- Spatial index information
- Whether the feature class is m–aware or z–aware
- The spatial reference information
Feature classes created within 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.
The class identifier (CLSID) parameter is used to specify the globally unique identifier (GUID) to instantiate the object representing a feature in that FeatureClass. If null or nothing is passed in for the CLSID, the geodatabase defaults to the CLSID corresponding to esriGeoDatabase.Feature, which in most cases is acceptable. If you know the FeatureClass has a custom feature other than esriGeoDatabase.Feature, you can pass in its GUID at this time or later call methods on the FeatureClass's IClassSchemaEdit interface.
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 you pass in null or nothing for the EXTCLSID, the new FeatureClass will not have a ClassExtension.
Since ClassExtensions are not required, this is usually alright unless the feature class being created is of type annotation, dimension lines, or a custom FeatureClass that requires a ClassExtension. If you know the FeatureClass has a ClassExtension and you know the GUID for the ClassExtension, you can pass it in at this time or later call methods on the FeatureClass's IClassSchemaEdit interface.
The feature type parameter specifies the category type of features stored in the feature class. See the following table:
Feature type
|
Real-world object or concept
|
esriFTSimple | Polygons, polylines, and points representing objects or places that have area, such as water bodies; linear objects, such as rivers; and localized positions, such as houses or sample sites. |
esriFTSimpleJunction | Simple junction feature in a geometric network representing point objects, such as a fuse, service point, or telephone pole. |
esriFTSimpleEdge | Simple edge feature in a geometric network representing polyline objects, such as primary or secondary overheads. |
esriFTComplexJunction | Complex junction feature in a geometric network, not in general use. |
esriFTComplexEdge | Complex edge feature in a geometric network representing polyline objects such as primary overheads, which have midspan connectivity. Network resources flow through complex edge without interruption by midspan connectivity. |
esriFTAnnotation | Place or object names or identifiers, such as street names, hydrant ID numbers, land values, or elevation. |
esriFTCoverageAnnotation | Place or object names or identifiers, such as street names, hydrant ID numbers, land values, or elevation. Not supported in geodatabases, only supported in coverage datasets. |
esriFTDimension | Measurements, such as distances, lengths, widths, and depths. |
esriFTRasterCatalogItem
|
A raster dataset in a raster catalog that has information, such as footprints, names, metadata, and any other user-defined attributes.
|
Identifies the name of the field of type geometry in the fields collection that represents the Shape field of the feature class.
The optional configurationKeywordparameter 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 the case of an Oracle database, the configuration keyword controls the table space where the table is created, as well as the initial and next extents, and other properties.
The configurationKeywords 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. For more information on configuration keywords, refer to the ArcSDE documentation. The configuration keywords for a file geodatabase are predefined. In most cases, you will use the Defaults keyword. See the following code example:
[Java]
static IFeatureClass createFeatureClass(IFeatureDataset featureDataset, String
nameOfFeatureClass)throws Exception{
//This function creates a new feature class in a supplied feature dataset by building all of the
//fields from scratch. IFeatureClassDescription (or IObjectClassDescription if the table is
//created at the workspace level) can be used to get the required fields and are used to
//get the InstanceClassID and ExtensionClassID.
//Create new fields collection with the number of fields you plan to add. Must add at least two fields
//for a feature class: Object ID and Shape field.
IFields fields = new Fields();
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
fieldsEdit.setFieldCount(3);
//Create Object ID field.
IField fieldUserDefined = new Field();
IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined;
fieldEdit.setName("OBJECTID");
fieldEdit.setAliasName("OBJECT ID");
fieldEdit.setType(esriFieldType.esriFieldTypeOID);
fieldsEdit.setFieldByRef(0, fieldUserDefined);
//Create Shape field.
fieldUserDefined = new Field();
fieldEdit = (IFieldEdit)fieldUserDefined;
//Set up geometry definition for the Shape field.
//You do not have to set the spatial reference, as it is inherited from the feature dataset.
IGeometryDef geometryDef = new GeometryDef();
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.setGeometryType(esriGeometryType.esriGeometryPolyline);
//By setting the grid size to 0, you are allowing ArcGIS to determine the appropriate grid sizes for the feature class.
//If in a personal geodatabase, the grid size is 1,000. If in a file or ArcSDE geodatabase, the grid size
//is based on the initial loading or inserting of features.
geometryDefEdit.setGridCount(1);
geometryDefEdit.setGridSize(0, 0);
geometryDefEdit.setHasM(false);
geometryDefEdit.setHasZ(false);
//Set standard field properties.
fieldEdit.setName("SHAPE");
fieldEdit.setType(esriFieldType.esriFieldTypeGeometry);
fieldEdit.setGeometryDefByRef(geometryDef);
fieldEdit.setIsNullable(true);
fieldEdit.setRequired(true);
fieldsEdit.setFieldByRef(1, fieldUserDefined);
//Create a field of type double to hold some information for the features.
fieldUserDefined = new Field();
fieldEdit = (IFieldEdit)fieldUserDefined;
fieldEdit.setName("Avg_income");
fieldEdit.setAliasName("Average income for 1999-2000");
fieldEdit.setEditable(true);
fieldEdit.setIsNullable(false);
fieldEdit.setPrecision(2);
fieldEdit.setScale(5);
fieldEdit.setType(esriFieldType.esriFieldTypeDouble);
fieldsEdit.setFieldByRef(2, fieldUserDefined);
//Create a feature class description object to use for specifying the CLSID and EXTCLSID.
IFeatureClassDescription fcDesc = new FeatureClassDescription();
IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
return featureDataset.createFeatureClass(nameOfFeatureClass, fields,
ocDesc.getInstanceCLSID(), ocDesc.getClassExtensionCLSID(),
esriFeatureType.esriFTSimple, "SHAPE", "");
}
See Also:
How to create a feature datasetHow to create a stand-alone feature class in a geodatabase
How to create new fields
How to create an object class within a geodatabase
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime: Geodatabase Update |