[Visual Basic 6.0]
Public Sub FeatureBufferCode()
Dim pWorFact As IWorkspaceFactory
Dim pWor As IWorkspace
Dim pFeatWor As IFeatureWorkspace
Dim pWorEdit As IWorkspaceEdit
Dim pFC As IFeatureClass
Dim pFeatureBuffer As IFeatureBuffer
Dim pFeatureCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pPolyline As IPolyline
Dim pt As IPoint
Dim q As Long, i As Long
Set pWorFact = New AccessWorkspaceFactory
Set pWor = pWorFact.OpenFromFile("D:\Testing\Data\GDB1.mdb", 0)
Set pFeatWor = pWor
Set pWorEdit = pWor
Set pFC = pFeatWor.OpenFeatureClass("casing")
pWorEdit.StartEditing True
pWorEdit.StartEditOperation
Set pFeatureBuffer = pFC.CreateFeatureBuffer
Set pFeatureCursor = pFC.Insert(True)
Set pFeature = pFeatureBuffer
Set pPolyline = New Polyline
'Create 100 features using FeatureBuffer and insert into a feature cursor
For i = 0 To 99
'Create the polyline geometry to assign to the new feature
Set pt = New Point
pt.X = 2213300 + i
pt.Y = 396500 + i
pPolyline.FromPoint = pt
Set pt = New Point
pt.X = 2213300 + i
pt.Y = 396500 + i
pPolyline.ToPoint = pt
'Set the feature's shape
Set pFeature.Shape = pPolyline
'Insert the feature into the feature cursor
q = pFeatureCursor.InsertFeature(pFeatureBuffer)
Next i
'Flush the feature cursor to the database
pFeatureCursor.Flush
pWorEdit.StopEditOperation
pWorEdit.StopEditing True
End Sub
[C#]//IFeatureBuffer Example
public void IFeatureBuffer_Example(IFeatureClass featureClass)
{
//Function is designed to work with polyline data
if (featureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) { return; }//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
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();//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.
//Create 100 features using FeatureBuffer and insert into a feature cursor
ESRI.ArcGIS.Geometry.IPolyline polyline = new ESRI.ArcGIS.Geometry.PolylineClass();
ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
for (int i = 0; i < 100; i++)
{
//Create the polyline geometry to assign to the new feature
point.X = 498490 + i * 10;
point.Y = 675380 + i * 10;
polyline.FromPoint = point;
point = new ESRI.ArcGIS.Geometry.PointClass();
point.X = 498480 + i * 10;
point.Y = 675390 + i * 10;
polyline.ToPoint = point;
featureBuffer.Shape = polyline;//Insert the feature into the feature cursor
featureOID = featureCursor.InsertFeature(featureBuffer);
}
//Flush the feature cursor to the database
//Calling flush allows you to handle any errors at a known time rather then on the cursor destruction.
featureCursor.Flush();//Stop editing
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);//Release the Cursor
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
}
[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button
in the upper-left corner of the page.