English

Bug: ArcObjects: IFeatureRenderer::ExclusionSet does not exclude any features

Description

When working with ArcMap feature layers and feature renderer objects in Visual Basic for Applications (VBA), setting IFeatureRenderer::ExclusionSet does not exclude any features from drawing. This problem occurs when working with these objects in any supported language, including VBA and C++.

Cause

The feature layer's exclusion set always overrides the renderer's exclusion set. This override occurs even if the feature layer's exclusion set is empty.

In ArcObjects terminology, IGeoFeatureLayer::ExclusionSet always overrides IFeatureRenderer::ExclusionSet.

Workaround

To exclude features from drawing, set IGeoFeatureLayer::ExclusionSet.

  1. Paste the following code into the ArcMap VBA editor.
    Code:

    Sub ExclusionSetOnGeoLayer()
    1 Dim pMxDoc As IMxDocument
    2 Dim pMap As IMap
    3 Dim pAV As IActiveView
    4 Dim pWSF As IWorkspaceFactory
    5 Dim pWS As IFeatureWorkspace
    6 Dim pFC As IFeatureClass
    7 Dim pFL As IFeatureLayer
    8 Dim pTable As ITable
    9 Dim pLayer As IFeatureLayer
    10 Dim pGeoLayer As IGeoFeatureLayer
    11 Dim pFIDSet As IFeatureIDSet
    12 Dim pSimpleRenderer As ISimpleRenderer
    13 Dim pFeatureRenderer As IFeatureRenderer
    14 Dim pSymbol As IFillSymbol
    15 Dim pColor As IRgbColor
    16 Dim i As Integer
    17
    18 Set pMxDoc = ThisDocument
    19 Set pWSF = New ArcInfoWorkspaceFactory
    20 Set pWS = pWSF.OpenFromFile("C:\ArcGIS\arcexe81\ArcObjects Developer Kit\Samples\Data\canada", 0) 'Change this
    21 Set pFC = pWS.OpenFeatureClass("canada:polygon") 'Change this
    22
    23 'Get create the layer and sock the FC into it.
    24 Set pLayer = New FeatureLayer
    25 Set pLayer.FeatureClass = pFC
    26 pLayer.Name = pFC.FeatureDataset.Name
    27
    28 'Determine how many features are in the FC.
    29 Set pTable = pFC
    30 Dim iCount As Integer
    31 iCount = pTable.RowCount(Nothing) / 2
    32
    33 'Fill the exclusion IDSet with number of features/2.
    34 Set pFIDSet = New FeatureIDSet
    35
    36 For i = 2 To iCount
    37 pFIDSet.Add i
    38 Next i
    39
    40 Set pGeoLayer = pLayer
    41 Set pSimpleRenderer = New SimpleRenderer
    42 Set pSymbol = New SimpleFillSymbol
    43 Set pColor = New RgbColor
    44 pColor.Red = 250
    45 pSymbol.Color = pColor
    46 Set pSimpleRenderer.Symbol = pSymbol
    47
    48 Set pFeatureRenderer = pSimpleRenderer
    49 Set pFeatureRenderer.ExclusionSet = pFIDSet 'ExclusionSet on Renderer
    50 ' Set pGeoLayer.ExclusionSet = pFIDSet 'Uncomment this line to see IGeoFeatureLayer::ExclusionSet work
    51 Set pGeoLayer.Renderer = pFeatureRenderer
    52
    53 Set pAV = pMxDoc.FocusMap
    54 Set pMap = pAV
    55 pMap.AddLayer pLayer
    56 pAV.Refresh
    57 MsgBox "Half of the polygons should be missing." & Chr(13) & "To see proper result uncomment line 50."
    End Sub

  2. Change lines 20 and 21 to reflect the name and location of the data being used.
  3. Run the macro.

    Note:
    Notice that no features are excluded from drawing.

  4. Uncomment line 50 and run the macro again.

    Note:
    Half of the features should now be excluded from drawing.

Related Information