ArcObjects Library Reference  (GeoDatabase)    

IFeatureClass.CreateFeatureBuffer Method

Create a feature buffer that can be used with an insert cursor.

[Visual Basic 6.0]
Function CreateFeatureBuffer As IFeatureBuffer
[Visual Basic .NET]
Public Function CreateFeatureBuffer ( _
) As IFeatureBuffer
[C#]
public IFeatureBuffer CreateFeatureBuffer (
);
[Java]
public IFeatureBuffer createFeatureBuffer (
)
throws
    IOException,
    AutomationException
[C++]
HRESULT CreateFeatureBuffer(
  IFeatureBuffer** buffer
);
[C++]

Parameters

buffer [out, retval]

  buffer is a parameter of type IFeatureBuffer

Product Availability

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

Remarks

The CreateFeatureBuffer method creates a feature buffer and returns the IFeatureBuffer interface. This can be used to create new features in the feature class with an insert cursor. Like creating a feature with IFeatureClass::CreateFeature, the field values for the new feature must be initialized to some value before it can be stored in the database. All edits to features that participate in a Topology or Geometric Network must be performed within an edit session and bracketed within an edit operation.

Calling the CreateFeatureBuffer method in IFeatureClass has the same effect as calling the CreateRowBuffer interface in ITable except that the IFeatureClass methods return an IFeatureBuffer interface on the created row buffer.

[Visual Basic 6.0]

The following example shows how you can use a IFeatureBuffer and a IFeatureCursor to insert a new feature into the feature class.


 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

'create a feature cursor and feature buffer interface
Dim pFeatCur As IFeatureCursor
Dim pFeatBuf As IFeatureBuffer

'open the feature cursor and feature buffer
Set pFeatCur = pFeatcls.Insert(True)
Set pFeatBuf = pFeatcls.CreateFeatureBuffer

'get the list of fields
Dim pFlds As IFields
Dim pFld As IField
Dim i As Long
Dim pPolygon As IPolygon
Dim pPolyline As IPolyline
Dim pPt As IPoint

Set pPolygon = New Polygon
Set pPolyline = New Polyline
Set pPt = New Point

'find the geometry field, based on the shape type,
'set the value for the field to the appropriate object
Set pFlds = pFeatcls.Fields
For i = 1 To pFlds.FieldCount - 1
Set pFld = pFlds.Field(i)

If (pFld.Type = esriFieldTypeGeometry) Then
Dim pGeom As IGeometry
Select Case pFeatcls.ShapeType
Case esriGeometryPolygon
Set pGeom = pPolygon
Case esriGeometryPolyline
Set pGeom = pPolyline
Case esriGeometryPoint
Set pGeom = pPt
End Select

'set the value in the feature buffer
pFeatBuf.Value(i) = pGeom

'if it is not a geometry column, determine what kind of
'field it is, and insert the equivalent of a null value
'for that field type
Else
If pFld.Type = esriFieldTypeInteger Then
pFeatBuf.Value(i) = CLng(0)
ElseIf pFld.Type = esriFieldTypeDouble Then
pFeatBuf.Value(i) = CDbl(0)
ElseIf pFld.Type = esriFieldTypeSmallInteger Then
pFeatBuf.Value(i) = CInt(0)
ElseIf pFld.Type = esriFieldTypeString Then
pFeatBuf.Value(i) = ""
Else
MsgBox "Need to handle this field type"
End If
End If
Next i

'insert the feature from the buffer into the database
pFeatCur.InsertFeature pFeatBuf

See Also

IFeatureClass Interface | IFeature Interface | IFeatureCursor Interface

 


Feedback Send feedback on this page