Trim Unique Values


This sample consists of a VBA macro that updates unique values symbology for a layer based on values in the current layer data source.

The macro trims, i.e. removes, values from the layer's unique values renderer. There are two main options for this: 1) Trim all values not present in the current layer data source, and 2) Trim all values not present in the current extent for the layer.

This macro automates the process of removing values from a unique values symbology without disturbing the match between each individual values and symbols. In ArcObjects terminology, values are removed from the UniqueValuesRenderer that are not present in the current data (or current extent). Removing values from the renderer means that they will no longer appear in the ArcMap Table of Contents and Legend. This is particularly useful in the following scenarios:

a) to only see values present in the current extent

b) if the data behind the layer has been edited

c) if the layer now points to new data (a new feature class)

d) to synchronize unique values after importing symbology from a layer file (.lyr).

Note: the logic only removes values from the renderer, it does not add any new values to the renderer that it might find in the feature class/extent.
ArcView: VB6

Platforms: Windows

Requires: VB: An ArcMap session with states.shp loaded.

Minimum ArcGIS Release: 9.0

How to use:
  1. Open ArcMap and create a new map document.
  2. Use the 'Add Data' button to add ..\Program Files\ArcGIS\DeveloperKit\SamplesCOM\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.

Download the VB6 files
TrimUniqueValues.bas Module containing the macro

Download the files for all languages

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