HOW TO
You can use the following Avenue script to limit the classes displayed in a legend to only those that correspond to features within the current extent of the view.
Code:
'-- This script temporarily limits each theme to just the records
'-- in the display's extent and uses the built-in capability of a
'-- legend to return class counts to determine which classes
'-- it can dispense with. It is a general approach that
'-- does not need to worry about the details of each legend.
'-- Obtain the view's extent. It will be used to select the
'-- features for classification.
theView=av.GetActiveDoc
if (theView.Is(View).Not) then return NIL end
theExtent=theView.GetDisplay.ReturnExtent '-- Will select in the visible extents
'-- Process each active theme, if any.
sLog = "" ' Records what happens
for each theTheme in theView.GetActiveThemes
if (theTheme.Is(FTheme) and theTheme.CanSelect and
theTheme.CanReturnClassCounts) then
theFTab=theTheme.GetFtab
'
'-- Select visible features.
theFTab.RememberSelection
theTheme.SelectbyRect(theExtent,#VTAB_SELTYPE_NEW)
'
'-- Limit the theme to the selected features.
theFTab.SetDefBitmap(theFTab.GetSelection.Clone)
theFTab.UpdateDefBitmap
'
'-- Remove unused classes from the legend.
lstCounts = theTheme.ReturnClassCounts
lstClassifications = theTheme.GetLegend.GetClassifications
lstSymbols = theTheme.GetLegend.GetSymbols
n = 0 ' Counts the number of classes removed.
for each i in lstClassifications.Count-2..0 by -1 ' Skip the NoData class
if (lstCounts.Get(i) = 0) then
lstClassifications.Remove(i)
lstSymbols.Remove(i)
n = n+1
end
end
theTheme.UpdateLegend ' Cause the legend to redraw in the TOC
'
'-- Log the changes.
if (n = 1) then sClass = "class" else sClass = "classes" end
sLog = sLog + NL + "[" + theTheme.GetName + "]: " +
n.AsString ++ sClass ++ "removed."
'
'-- Restore the original definition and selection.
theFTab.SetDefinition(theFTab.GetDefinition)
theFTab.UpdateDefBitmap
theFTab.SetSelection(theFTab.GetLastSelection)
else '-- This is an image or grid theme, most likely.
sLog = sLog + NL + "[" + theTheme.GetName + "] could not be modified."
end
end
'-- Summarize results.
if (sLog <> "") then
MsgBox.Report("Summary of changes made to legends:" + NL + sLog, Script.The.GetName)
end
'-- End of Script
Get help from ArcGIS experts
Download the Esri Support App