Last active
August 29, 2015 14:21
-
-
Save cindygis/7675e358b81a6e35835d to your computer and use it in GitHub Desktop.
Updates the values for a unique symbology renderer based on range domain values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @date 27/05/2015 | |
# @author Cindy Williams | |
# | |
# Updates the values for a unique symbology renderer | |
# based on range domain values. The layer must have | |
# the unique symbols renderer enabled manually. | |
# | |
# For use in the Python window in ArcMap. | |
# | |
import arcpy | |
mxd = arcpy.mapping.MapDocument("CURRENT") | |
lyr = arcpy.mapping.ListLayers(mxd)[4] # 5th layer in TOC | |
rvd_name = "rvd_1_12" # Name of range value domain | |
rvd_values = [] | |
# Courtesy of pythoncentral.io - works like range(), but for floats | |
# The range domain type is Short, but the min and max are stored as floats | |
def frange(start, stop, step): | |
i = start | |
while i < stop: | |
yield i | |
i += step | |
# Check if the layer has the unique symbology renderer | |
if lyr.symbologyType == 'UNIQUE_VALUES': | |
# Access domains in the workspace using ListDomains | |
for domain in arcpy.da.ListDomains(lyr.workspacePath): | |
# Check for name | |
if domain.name == rvd_name: | |
for n in frange(dom.range[0], dom.range[1] + 1, 1): | |
# Can't append directly into classValues | |
rvd_values.append(int(n)) | |
lyr.symbology.classValues = rvd_values # Set unique value list | |
arcpy.RefreshTOC() | |
mxd.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment