RemoveUniqueValsNotPresent

Created:12/06/2001
Description:

This sample consists of a VBA macro that updates unique values symbology for a layer by looking at the data currently "behind" the layer. Essentially, the macro automates the manual process of removing "Zero count" values from a unique values symbology without disturbing the match between each individual value and symbol. In ArcObjects lingo, Values are removed from the UniqueValuesRenderer that are not present in the current data. Removing values from the renderer means that they will no longer appear in the ArcMap Table of Contents and Legend. This is particularly useful: a) if the data behind the layer has been edited b) if the layer now points to new data (a new feature class), or c) to synchronize unique values symbology imported from a layer file (.lyr) with the currently referenced data. Note: the logic only removes values from the renderer that are not present in the reference feature class, it does not add any new values to the renderer that it might find in the feature class. Also, layer definition queries are respected.

How to use:
  1. Open ArcMap and create a new map document.
  2. Use the 'Add Data' button to add ..\arcgis\arcexe83\ArcObjects Developer Kit\Samples\Data\Usa\states.shp to your map.
  3. Set up Unique values symbology based on the 'SUB_REGION' field. Add all values and check off the 'All other values' class. Press Apply.
  4. To demonstrate, set a Definition query (Layer properties dialog > Definition Query tab) that removes several values. For example, use this query: "SUB_REGION" <> 'Pacific' AND "SUB_REGION" <> 'Mtn'. Press Ok.
  5. Create a new macro (Tools--> Macros--> Create). Copy the code provided in RemoveUniqueValsNotPresent.bas and paste into the Visual Basic Editor of your map document.
  6. Run the macro. 'Pacific' and 'Mtn' are removed from the Table of Contents.

Application:
ArcMap

Requires: An ArcMap session with states.shp loaded.

Difficulty: Intermediate


Visual Basic
File Description
RemoveUniqueValsNotPresent.bas Module containing the macro


Key CoClasses: UniqueValueRenderer
Key Interfaces: IUniqueValueRenderer, IFeatureLayerDefinition
Key Members: IFeatureLayerDefinition::DefinitionExpression