Last active
March 29, 2023 22:14
-
-
Save bixb0012/dfddcd1142b31b2986cc9feb155d4564 to your computer and use it in GitHub Desktop.
ArcPy (ArcMap): Modify Layer Symbology, Expanded
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
#!python2 | |
# Example 1a adapted from https://www.reddit.com/r/gis/comments/4rhvhh/map_automation_arcpymapping_make_lyr/ | |
# | |
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm | |
# 2) https://docs.python.org/2/library/json.html | |
import arcpy | |
import json | |
lyr = # Layer object, typically from arcpy.mapping.ListLayers (arcpy._mapping.Layer) | |
# Example 1a: Modifying single-field renderer using undocumented _arc_object.renderer | |
new_field = # New field name for symbolizing layer | |
old_field = # Old field name for symbolizing layer | |
sym_xml = lyr._arc_object.renderer | |
lyr._arc_object.renderer = sym_xml.replace(old_field, new_field) | |
arcpy.RefreshActiveView() | |
# Example 1b: Modifying single-field renderer using updateLayerFromJSON | |
new_field = # New field name for symbolizing layer (string) | |
sym_dict = json.loads(lyr._arc_object.getsymbology()) | |
sym_dict["renderer"]["field1"] = new_field | |
lyr.updateLayerFromJSON(json.dumps({"drawingInfo": sym_dict})) | |
arcpy.RefreshActiveView() | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, i used this as a guide to write a function to update symbology to only show classes with values instead of all the existing classes