Buffer Snapping

Created:12/17/2000
Description:

This code demonstrates how to create a snapping agent based on a buffer around the points of the specified feature class. For electrical data sets it is common to want to snap primary lines to the outside of the symbol representing a pole. To make this happen you will need to specify that you want pole symbols to scale, then use this snapping agent with an appropriate buffer distance (based on the size of the pole symbol).

How to use:
  1. Register the dll on your machine.
  2. Using Categories, register this class in the 'ESRI Snap Agents' component category.
  3. Start an edit session with at least one point layer loaded.
  4. Start VBA and paste in the VBA code from below. In References add 'BufferSnapPrj'.
  5. Open up the snapping dialog and turn on the "Buffer Snap" agent.
  6. Begin adding new features and you will be able to snap to buffers around the features in the specified feature class.
Public Sub SetBufferSnapClass()
  On Error Resume Next
  Dim pApp As IApplication, pMap As IMap, pFeatLayer As IFeatureLayer
  Dim pEditor As IEditor
  Dim pSnapAgent As ISnapAgent
  Dim pSnapEnv As ISnapEnvironment
  Dim pEditLayers As IEditLayers
  Dim pMySnapAgent As BufferSnapPrj.BufferSnap
  Dim pUID As New UID
  Dim Count As Integer, Count2 As Integer

  pUID = "esriCore.Editor"
  Set pApp = Application
  Set pEditor = pApp.FindExtensionByCLSID(pUID)
  Set pEditLayers = pEditor
  Set pSnapEnv = pEditor
  Set pMap = pEditor.Map
  'Find custom snap agent and set is featureclass property
  For Count2 = 0 To pMap.LayerCount - 1
    If UCase(pMap.Layer(Count2).Name) = "POLES" Then
      For Count = 0 To pSnapEnv.SnapAgentCount - 1
        Set pSnapAgent = pSnapEnv.SnapAgent(Count)
        If pSnapAgent.Name = "Buffer Snap" Then
          Set pMySnapAgent = pSnapAgent
          Set pFeatLayer = pMap.Layer(Count2)
          pMySnapAgent.FeatureClass = pFeatLayer.FeatureClass
        End If
      Next Count
      Exit For
    End If
  Next Count2

End Sub
		
Application: ArcMap

Requires: Point feature class

Difficulty: Moderate


Visual Basic
File Description
BufferSnap.cls Class file containing buffer snapping agent.


Key CoClasses: FeatureSnap, FeatureCache, Point
Key Interfaces: ISnapAgent, IFeatureCache, ITopologicalOperator
Key Members: ISnapAgent::Snap, IFeatureCache::Initialize, IFeatureCache::AddFeatures, ITopologicalOperator::Buffer