How to add overrides to feature representations


This sample will show you how to copy contents from Shape field of one feature class to Override field of another feature class representation. For example, if you have two point feature classes, and the features in one feature class have been moved from original location for cartographic purposes then this information can be copied to a different feature class representation as overrides and stored in the override field. If you wish to remove the overrides from the override field, run the GeoProcessing Tool 'Remove Override' from the toolbar Cartography Tools -> Representation Management.

How to use

  1. Add a Geodatabase point feature class and feature class representation to ArcMap. Set the representation renderer for the representation layer.
  2. Copy/paste the macro code into VBA.
  3. Change the names of feature layers and common field to match your data.
  4. Run the macro.
[VBA]
'Use this sample to add Shape information of point features (pFClass) which have
'been moved from their original locations to the Override (blob) field of a different feature class
'representation (pRepClass). The feature class representation must have one BasicMarkerSymbol in the
'representation rule. The name of the field which is common to both the feature classes should be changed
'prior to running the code.


Option Explicit

Public Sub Test()
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pFeatLayer As IFeatureLayer, pGeoFeatLayer As IGeoFeatureLayer
    Dim pFeatClassWithReps As IFeatureClass, pMovedFeatClass As IFeatureClass
    Dim pRepRenderer As IRepresentationRenderer
    Dim pRepClass As IRepresentationClass
    Dim pRepRules As IRepresentationRules
    Dim pRepRule As IRepresentationRule
    Dim pRepresentation As IRepresentation
    Dim pBasicMarkerSymbol As IBasicMarkerSymbol
    Dim pMarkerPlacement As IMarkerPlacement
    Dim pGraphicAttributes As IGraphicAttributes
    Dim i As Integer, lID As Long
    Dim sName As String
    Dim pMapContext As IMapContext
    Dim pDisp As IDisplayTransformation
    Dim pFeature As IFeature, pMovedFeature As IFeature
    Dim pRepFCCursor As IFeatureCursor, pMovedFCCursor As IFeatureCursor
    Dim pQF As IQueryFilter, pQFMoved As IQueryFilter
    Dim pMovedPoint As IPoint, pPoint As IPoint
    Dim xDiff As Double, yDiff As Double
    Dim pOffsetPoint As IPoint, pMapPoint As IPoint
    
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    'walk through the layers and get feature layer which has representations
    For i = 0 To pMap.LayerCount - 1
        If pMap.Layer(i).Name = "US_Major_Cities_Project" Then 'Change to match your data
            Set pFeatLayer = pMap.Layer(i)
            Set pFeatClassWithReps = pFeatLayer.FeatureClass
            Exit For
        End If
    Next i
    
    'get the feature layer's representation class
    Set pGeoFeatLayer = pFeatLayer
    If TypeOf pGeoFeatLayer Is RepresentationRenderer Then
        Set pRepRenderer = pGeoFeatLayer.Renderer
        Set pRepClass = pRepRenderer.RepresentationClass
        Set pRepRules = pRepClass.RepresentationRules
    Else
        MsgBox "Layer is not a representation renderer"
        Exit Sub
    End If
    
    'walk through the representation rules and get a specific rule with given name
    pRepRules.Reset
    pRepRules.Next lID, pRepRule
    Do Until pRepRule Is Nothing
        If pRepRules.Name(lID) = "Rule1" Then Exit Do 'Change to match your data
        pRepRules.Next lID, pRepRule
    Loop
    
    If TypeOf pRepRule.Layer(0) Is IBasicMarkerSymbol Then
        Set pBasicMarkerSymbol = pRepRule.Layer(0)
        Set pMarkerPlacement = pBasicMarkerSymbol.MarkerPlacement
        Set pGraphicAttributes = pMarkerPlacement
    Else
        MsgBox "Symbol layer is not a BasicMarkerSymbol"
        Exit Sub
    End If
    
    'walk through the layers and get feature class where features have been moved
    For i = 0 To pMap.LayerCount - 1
        If pMap.Layer(i).Name = "US_Major_Cities_Repositioned_Project" Then 'Change to match your data
            Set pFeatLayer = pMap.Layer(i)
            Set pMovedFeatClass = pFeatLayer.FeatureClass
            Exit For
        End If
    Next i
    
    'for each representation, calculate the xdiff and ydiff values in mapcontext units
    Set pMapContext = New MapContext
    Set pDisp = pMxDoc.ActiveView.ScreenDisplay.DisplayTransformation
    pMapContext.InitFromDisplay pDisp
    Set pRepFCCursor = pFeatClassWithReps.Update(New QueryFilter, False)
    Set pFeature = pRepFCCursor.NextFeature
    Do Until pFeature Is Nothing
        Set pRepresentation = pRepClass.GetRepresentation(pFeature, pMapContext)
        sName = pFeature.Value(pFeature.Fields.FindField("NAME")) 'Change to match your data
        Set pPoint = pFeature.Shape
        
        'get the corresponding feature which has been repositioned
        Set pQFMoved = New QueryFilter
        pQFMoved.AddField "NAME"
        pQFMoved.WhereClause = "NAME='" + sName + "'"
        Set pMovedFCCursor = pMovedFeatClass.Search(pQFMoved, False)
        'assume only one match so get only one feature
        Set pMovedFeature = pMovedFCCursor.NextFeature
        Set pMovedPoint = pMovedFeature.Shape 'Shape of the moved feature
        
        xDiff = pMovedPoint.X - pPoint.X 'X offset between representation feature and moved feature
        yDiff = pMovedPoint.Y - pPoint.Y 'Y offset between representation feature and moved feature
        
        Set pOffsetPoint = New Point
        pOffsetPoint.PutCoords xDiff, yDiff
        Set pMapPoint = New Point
        Set pMapPoint = pMapContext.FromGeographyToMap(pOffsetPoint)
        
        'add attribute overrides for representation feature
        pRepresentation.Value(pGraphicAttributes, 0) = pMapPoint.X 'Marker placement's X Offset
        pRepresentation.Value(pGraphicAttributes, 1) = pMapPoint.Y 'Marker placement's Y Offset
        pRepresentation.UpdateFeature 'update the representation feature since changes have been made
        pFeature.Store 'Store the feature to persist changes
        
        Set pFeature = pRepFCCursor.NextFeature
    Loop
    
    '** Refresh the TOC '** Draw the map
    pMxDoc.ActiveView.Refresh
End Sub






Additional Requirements
  • An edit session with geodatabase feature representation class