I have a shapefile that is a 10-by-10 grid of squares. The shapefile has 50 attribute columns (named p_1 through p_50) where each column has 100 entries (corresponding to the 100 grid squares) and each entry is one of 1, 2, 3, 4, or 5.
In order to visualize p_1, I navigate to Layer Properties, click on the Symbology tab, and click on 'Unique values' which is listed under Categories. I then select 'p_1' from the Value Field, click the 'Add All Values' button, and click the 'Apply' button. This results in a grid where each square has a color based on the number corresponding to the grid square in the p_1 column of the shapefile attribute table. I then use the Export Map feature to save the colored grid as a png.
However, because there 50 columns corresponding to 50 different plans, I would like to automate this process.
How do I automate this process?
With help from @Fezter the following code accomplishes most of what I want:
import arcpy
mxd = arcpy.mapping.MapDocument("current")
# Find the plan layer
kdp_lyr = None
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == 'kd_plans':
kdp_lyr = lyr
break
num_plans = 50
for i in range(0, num_plans):
if kdp_lyr.symbologyType == "UNIQUE_VALUES":
kdp_lyr.symbology.valueField = "all_the_plans$.plan_" + str(i)
kdp_lyr.symbology.addAllValues()
## Remove the Null value
sourceList = kdp_lyr.symbology.classValues
sourceList.remove("<Null>")
kdp_lyr.symbology.classValues = sourceList
kdp_lyr.symbology.showOtherValues = False
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPNG(mxd, 'plan_' + str(i) + '.png')
del mxd
The one thing it does not do is use the same color for each value (e.g., blue for the number 1 value across all plans i).
@Michael Miles-Stimson suggested using Apply Symbology from Layer however I don't believe this will work in my case because according to the documentation:
The field in the Input Layer that will be displayed must have the same name as that of the corresponding Symbology Layer field. If this field is missing, the output data is drawn with default symbology.
and each field in my Input Layer has a different name.