Forked from bixb0012/arcpy_arcmap_modify_layer_symbology_expanded.py
Created
March 30, 2018 10:23
-
-
Save AhmedElAtari/7cbf18e60ac0467da1c00f9949fb136b 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
# 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