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.
The IFeatureWorkspace.CreateFeatureClass method can be used to create a stand-alone feature class that is not part of a FeatureDataset. To get a reference to the IFeatureWorkspace interface, cast from a geodatabase workspace.
For more information on how to connect to a workspace, see How to connect to a geodatabase. For steps on how to create a new geodatabase, see How to create new geodatabases.
Assuming you have a reference to a workspace (called workspace), the following code example can be used to cast to IFeatureWorkspace:
[Java]
IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(workspace);
While similar to the IFeatureWorkspace.CreateTable method, CreateFeatureClass has some additional parameters, since it creates feature classes instead of tables:
- A FeatureType parameter that specifies the category of features to be stored in this feature class (such as, esriFTSimple, esriFTComplexEdgeFeature, and so on)
- A shapeFieldName corresponding to the name of shape field—the ShapeFieldName identifies the name of the field in the input fields collection, of type Geometry that represents the shape field for the feature class
The following discusses the other arguments to the CreateFeatureClass method:
The feature class name uniquely identifies it in the geodatabase. The name you specify cannot contain spaces or punctuation or start with a number. Make sure 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. 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 the 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 a new or existing feature class, see 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 following:
- The geometry type
- Spatial index information
- Whether the feature class is m-aware or z-aware
- The spatial reference information
Feature classes created in a feature dataset inherit the spatial reference of the containing feature dataset. However, 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 steps on how to create a predefined spatial reference object, see How to create a predefined spatial reference.
There is a vast array of predefined spatial reference systems based on the values from the European Petroleum Survey Group's (EPSG) database (http://www.epsg.org), which is becoming an industry standard.
If you are creating feature datasets in different releases of the geodatabase, see How to construct a high or low precision spatial reference that shows you how to create spatial references in ArcGIS 9.2 and pre-9.2 geodatabases.
If you need to create a coordinate system with custom properties, see How to create a custom geographic coordinate system and How to create a custom projected coordinate system that shows you how to do these tasks.
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 acceptable 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. See the following code example:
[Java]
//Create a new UID and set its value to the type of feature class to create
UID CLSID = new UID();
CLSID.setValue("esriGeoDatabase.Feature");
//Use the IFeatureClassDescription interface
IFeatureClassDescription fcDesc = new FeatureClassDescription();
//The CLSID and ClassExtensionCLSID values will be supplied to the CreateFeatureClass method
fcDesc.getInstanceCLSID(), fcDesc.getClassExtensionCLSID()
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 edges 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.
|
This 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, 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(IFeatureWorkspace featureWorkspace, String
nameOfFeatureClass, ISpatialReference spatialReference)throws Exception{
//This function creates a new standalone feature class in a supplied workspace by building all of the
//fields from scratch. IFeatureClassDescription is used to get the InstanceClassID and ExtensionClassID
//Create new Fields collection with the number of fields we plan to add. Must add at least 2 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
IGeometryDef geometryDef = new GeometryDef();
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.setGeometryType(esriGeometryType.esriGeometryPolyline);
//By setting our grid size to 0, we're allowing ArcGIS to determine appropriate grid sizes for the feature class
//If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size
//will be based on the initial loading or inserting of features.
geometryDefEdit.setGridCount(1);
geometryDefEdit.setGridSize(0, 0);
geometryDefEdit.setHasM(false);
geometryDefEdit.setHasZ(false);
//Assign the spatial reference that was passed in, possibly from
//IGeodatabase::SpatialReference for the containing feature dataset.
if (spatialReference != null){
geometryDefEdit.setSpatialReferenceByRef(spatialReference);
}
//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 featureWorkspace.createFeatureClass(nameOfFeatureClass, fields,
ocDesc.getInstanceCLSID(), ocDesc.getClassExtensionCLSID(),
esriFeatureType.esriFTSimple, fcDesc.getShapeFieldName(), "");
}
See Also:
How to create an object class within a geodatabaseHow to create a feature class within a feature dataset
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime: Geodatabase Update |