Knowledge Base - Technical Articles
HowTo: Automatically display feature counts in the ArcMap TOC and legends
| Article ID: | 21494 |
|---|---|
| Software: | ArcGIS - ArcEditor 8.1, 8.1.2, 8.2, 8.3, 9.0, 9.1, 9.2 ArcGIS - ArcInfo 8.1, 8.1.2, 8.2, 8.3, 9.0, 9.1, 9.2 ArcGIS - ArcView 8.1, 8.1.2, 8.2, 8.3, 9.0, 9.1, 9.2 |
| Platforms: | Windows NT 4.0, 2000, XP |
Summary
When writing VB/VBA code to create a UniqueValueRenderer, show feature counts in the ArcMap Table of Contents (TOC) and legends by appending the count for each class to the value that is specified for the class label.
Procedure
Follow one of two options given below:
- Option one
Use sample code:
ArcGIS 8.3
ArcObjects Online 8.3 - Unique Values Counts and Data Driven Descriptions
ArcGIS 9.0
ArcGIS Developer Online 9.0 - Unique Values Counts and Data Driven Descriptions
ArcGIS 9.1
ESRI Developer Network 9.1 - Unique Values Counts and Data Driven Descriptions
ArcGIS 9.2
ESRI Developer Network 9.2 - Unique Values Counts and Data Driven Descriptions
- Option two
Modify the example code from ArcObjects Online:
1. Find the example for IUniqueValueRenderer on ArcObjects Online, ArcGIS Developer Online, the ESRI Developer Network 9.1, or the ESRI Developer Network 9.2 and copy the example code.
2. Find this section in the code:If Not ValFound Then
pRender.AddValue x, "Name", symx
pRender.Label(x) = x
pRender.Symbol(x) = symx
End If
3. Replace with:If Not ValFound Then
Set pQueryFilter = Nothing
Set pQueryFilter = New QueryFilter
pQueryFilter.WhereClause = "NAME = '" & x & "'"
pRender.AddValue x, "Name", symx
pRender.Label(x) = x & " (" & pFeatCls.FeatureCount(pQueryFilter) & ")"
pRender.Symbol(x) = symx
End If
4. Run the code to apply the renderer to the layer. Feature counts should appear in the TOC.
This code may take a long time to execute with medium to large datasets.
5. As an option, it is possible to insert a legend in the layout. Labels with feature counts appear here as well.-show me-
Created: 1/28/2002
Last Modified: 9/10/2008
By Anonymous - 01/27/2003 6:43 AM
I just want the number and not color ramps etc. Is there just a simple code to do just that?