How To: Create graphic buffers of features using ArcObjects


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



  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
    For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  3. Right-click the UIButtonControl and select View Source.
  4. 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
  5. Modify the value which the '.ValueDistance' property is set to in the code. This is the buffer distance for the output graphics.
  6. Add a feature class to ArcMap. Either the feature class or the data frame must have a spatial reference defined.
  7. Select one or more features.
  8. Select the layer in the table of contents to be buffered.
  9. 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.