ArcObjects Library Reference  (GeoDatabase)    

IFeatureClass.Insert Method

Returns a cursor that can be used to insert new features.

[Visual Basic 6.0]
Function Insert(
    ByVal useBuffering As Boolean _
) As IFeatureCursor
[Visual Basic .NET]
Public Function Insert ( _
    ByVal useBuffering As Boolean _
) As IFeatureCursor
public IFeatureCursor Insert (
    bool useBuffering
public IFeatureCursor insert (
    Boolean useBuffering
  VARIANT_BOOL useBuffering,
  IFeatureCursor** Cursor


useBuffering [in]

  useBuffering is a parameter of type VARIANT_BOOL

Cursor [out, retval]

  Cursor is a parameter of type IFeatureCursor

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.


Insert opens an insert cursor on the feature class which can be used to insert new features into it.

Insert cursors can be used on a custom object, with guaranteed polymorphic behavior. Insert cursors can be used either inside or outside of an edit session. If used inside an edit session, the changes are not committed to the base table until the edit session is saved. Network feature classes, Topology feature classes, feature classes that participate in composite relationships or other relationships with messaging and some custom feature classes may only be updated within an edit session. If you attempt to use an insert cursor on one of these classes outside of an edit session, it will fail.  If the insert cursor is created outside of an edit operation and new features are inserted within an edit operation, the changes are commited to the base tables.  The additions to the base table cannot be undone.  In addition, all edits to features that participate in a Topology or Geometric Network must be bracketed within an edit operation.

If the insert cursor is used on non-simple features (such as network features), the cursor will revert to using IFeature::Store.

If you are creating custom features that do not have polymorphic behavior on creation, update and deletion, you can implement the IObjectClassInfo interface to set the CanBypassStoreMethod property to true. Doing this will cause the Geodatabase to bypass the custom feature implementation for update and insert cursors used with that custom feature class. Also, you can implement the IObjectClassInfo2 interface on the object class extension and return true to CanBypassEditSession method to indicate the those custom features can be updated outside of an edit session.



    public void IFeatureClass__Insert(IFeatureClass featureClass)
        //get the Workspace from the IDataset interface on the feature class
        IDataset dataset = (IDataset)featureClass;
        IWorkspace workspace = dataset.Workspace;
        //Cast for an IWorkspaceEdit
        IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;

        //Start an edit session and operation

        //Create the Feature Buffer
        IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
        //Create insert Feature Cursor using buffering = true.
        IFeatureCursor featureCursor = featureClass.Insert(true);

        object featureOID;

        //With a feature buffer you have the ability to set the attribute for a specific field to be
        //the same for all features added to the buffer.
        featureBuffer.set_Value(featureBuffer.Fields.FindField("InstalledBy"), "K Johnston");
        //Here you can set the featurebuffers's shape by setting the featureBuffer.Shape
        //to a geomerty that matched the featureclasses.

        //Insert the feature into the feature cursor
        featureOID = featureCursor.InsertFeature(featureBuffer);

        //Calling flush allows you to handle any errors at a known time rather then on the cursor destruction.

        //Stop editing

        //Release the Cursor

[Visual Basic 6.0]

The following code will insert a new feature into the feature class using an insert cursor.

 Dim pFeatcls As IFeatureClass
 Dim pFeatLayer As IFeatureLayer
 Dim pDoc As IMxDocument
 Dim pMap As IMap
 Set pDoc = ThisDocument
 Set pMap = pDoc.Maps.Item(0)
 Set pFeatLayer = pMap.Layer(0)
 Set pFeatcls = pFeatLayer.FeatureClass
 Dim pFeatCur As IFeatureCursor
 Dim pFeatBuf As IFeatureBuffer
 Dim v As Variant
 Set pFeatCur = pFeatcls.Insert(True)
 Set pFeatBuf = pFeatcls.CreateFeatureBuffer
 v = pFeatCur.InsertFeature(pFeatBuf) 

See Also

IFeatureClass Interface | IFeature Interface | IFeatureCursor Interface


Feedback Send feedback on this page