HOW TO
You can use Avenue to add a theme's legend classification information to the attribute table. The script in this article creates a new field and populates each record with the legend class label.
Code:
'-- Script: LEGEND2TABLE.AVE
'-- This script populates a feature theme attribute
'-- table with a new field containing the legend
'-- classification label string for the range
'-- that each record's value falls into.
'-- To use, make your View the active window,
'-- and make the desired theme active.
'-- Setup initial objects
theView = av.GetActiveDoc
theTheme = theView.GetActiveThemes.Get(0)
theFTab = theTheme.GetFTab
'-- See if the theme's attribute table can be edited
if (theFTab.CanEdit.Not)
then
MsgBox.Warning("The active theme's attribute table"+NL+
"cannot be edited.","Stop")
return nil
else
theFTab.SetEditable(true)
end
'-- Get the legend, its classification, and the legend field
theLegend = theTheme.GetLegend
theClassifications = theLegend.GetClassifications
legendField = theFTab.FindField(theLegend.GetFieldNames.Get(0))
'-- Find the width of the widest classification
'-- label and use it to set the width of the new
'-- range field to be added to the table
widestString = 5
listofClLabels = {}
for each cl in theClassifications
theLabel = cl.GetLabel
if (theLabel.Count > widestString)
then
widestString = theLabel.Count
end
end
newRgField = Field.Make
("RangeLabel",#FIELD_CHAR,widestString,0)
theFTab.AddFields({newRgField})
'-- For each record in the theme's attribute table,
'-- get the value in the legend field
for each rec in theFTab
legendFieldValue = theFTab.ReturnValue(legendField,rec)
'-- For each classification in the legend, determine
'-- which range contains the legend value for that field
for each cl in theClassifications
if (cl.Contains(legendFieldValue))
'-- Populate that cell with the range's label string
then
theFTab.SetValue(newRgField,rec,(cl.GetLabel))
break
end
end
end
'-- Stop editing the table
theFTab.SetEditable(false)
MsgBox.Info("Done","")
'-- End of Script: LEGEND2TABLE.AVE
Article ID:000003711
Get help from ArcGIS experts
Download the Esri Support App