HOW TO

Create graphic buffers of features using ArcObjects

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 8.x and 9.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

Instructions provide sample code to create a graphic buffer of selected features using IFeatureCursorBuffer.

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Procedure

 
  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
Note:
For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Paste the code below into the UIButtonControl's click event (by default, the subroutine "UIButtonControl1_Click").
Dim pDoc As IMxDocument
Dim pFCBuff As IFeatureCursorBuffer2
Dim pLayer As IFeatureLayer
Dim pFS As IFeatureSelection
Dim pSS As ISelectionSet
Dim pSpatRef As ISpatialReference
Dim pFeature As IFeature
Dim pFCursor As IFeatureCursor
Dim pCompGraphicsLayer As ICompositeGraphicsLayer

Set pDoc = ThisDocument

'Set feature layer as the selected layer in the TOC
Set pLayer = pDoc.SelectedLayer
Set pFS = pLayer 'QI

'Grab the featureselection's selected set of features
Set pSS = pFS.SelectionSet
Set pSpatRef = pDoc.FocusMap.SpatialReference

Set pCompGraphicsLayer = pDoc.FocusMap.BasicGraphicsLayer

pSS.Search Nothing, False, pFCursor

'Loop through the featurecursor
    Set pFCBuff = New FeatureCursorBuffer
    
    'set the properties for the featurecursorbuffer
    With pFCBuff
      Set .BufferSpatialReference = pSpatRef
      Set .DataFrameSpatialReference = pSpatRef
      .Dissolve = False
      Set .FeatureCursor = pFCursor
      Set .SourceSpatialReference = pSpatRef
      Set .SpatialReference = pSpatRef
      Set .TargetSpatialReference = pSpatRef
      .Units(pDoc.FocusMap.MapUnits) = 9
      
      'Specify the buffer distance here
      .ValueDistance = 10
    End With
    
    pFCBuff.BufferToGraphics pCompGraphicsLayer
pDoc.ActiveView.Refresh
  1. Modify the value which the '.ValueDistance' property is set to in the code. This is the buffer distance for the output graphics.
  2. Add a feature class to ArcMap. Either the feature class or the data frame must have a spatial reference defined.
  3. Select one or more features.
  4. Select the layer in the table of contents to be buffered.
  5. Click the new button to execute the code. The code produces graphic elements that belong to the FocusMap and are not associated with a feature class. The graphic elements represent a buffer zone of distance 'ValueDistance' around the selected features.

Article ID:000006279

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic