<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">来源:ArcEngine帮助文档</span>


  This topic explains how to create features in a geodatabase feature class. Two methods are shown, one that creates an individual feature using
the IFeatureClass.CreateFeature and IFeature.Store methods, and one that uses an insert cursor to execute a bulk load.

About creating features

The functionality available for feature creation is dependent on the following:
  • The license level the code runs on and the type of geodatabase it runs against.
  • The type of features that are being created—whether they are simple features, network features, created in a topology, and so on. For example, an ArcGIS for Desktop Standard or Advanced license is required to create features
    in the following:

    • Geometric network or topology
    • Dimension feature class
    • Annotation feature class
    • ArcSDE geodatabase, whether at the personal, workgroup, or enterprise level
The following are two primary ways to create features in the geodatabase: 
The following are the main differences between the two primary ways to create features in a geodatabase:
  • Calling IFeature.Store results in all object behavior being triggered. This includes—but is not limited to—behavior specific to network or annotation features and features that participate in a topology, as well as events, such
    as those from the IObjectClassEvents interface.
  • Insert cursors are used to bulk insert features in the geodatabase. Using an insert cursor and a feature buffer offers significantly faster performance for simple data loading and creation than creating features and storing
    them. The one catch is that when using the
    method, complex behavior and the triggering of events is not guaranteed.
  • The IObjectClassInfo and IWorkspaceEditControl interfaces can be used to enforce the calling of IFeature.Store by insert cursors, but this negates any performance advantages they offer.

If more than one simple feature is being created, always use an insert cursor for performance considerations.


The following code example demonstrates how to use the IFeatureClass.CreateFeature method and IFeature.Store to create a feature in a feature class containing pipes:


public static void CreateFeature(IFeatureClass featureClass, IPolyline polyline)
    // Build the feature.
    IFeature feature = featureClass.CreateFeature();
    feature.Shape = polyline;

    // Apply the appropriate subtype to the feature.
    ISubtypes subtypes = (ISubtypes)featureClass;
    IRowSubtypes rowSubtypes = (IRowSubtypes)feature;
    if (subtypes.HasSubtype)
        // In this example, the value of 3 represents the polymer vinyl chloride (PVC) subtype.
        rowSubtypes.SubtypeCode = 3;

    // Initialize any default values the feature has.

    // Update the value on a string field that indicates who installed the feature.
    int contractorFieldIndex = featureClass.FindField("CONTRACTOR");
    feature.set_Value(contractorFieldIndex, "K Johnston");

    // Commit the new feature to the geodatabase.

Using insert cursors

public static void InsertFeaturesUsingCursor(IFeatureClass featureClass, List <IGeometry > geometryList)
    using(ComReleaser comReleaser = new ComReleaser())   
        // Create a feature buffer.
        IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
        // Create an insert cursor.
        IFeatureCursor insertCursor = featureClass.Insert(true);
        // All of the features to be created are classified as Primary Highways.
        int typeFieldIndex = featureClass.FindField("TYPE");
        featureBuffer.set_Value(typeFieldIndex, "Primary Highway");
        foreach (IGeometry geometry in geometryList)        
  <span style="white-space:pre">	</span>{
            // Set the feature buffer's shape and insert it.
            featureBuffer.Shape = geometry;
        // Flush the buffer to the geodatabase.       
<span style="white-space:pre">	</span> insertCursor.Flush();


You may also like...