5

I have an template mxd I reference with several pre-defined layers. The only variable I need to modify is the color of certain symbols in the layer. I have tried to modify and dig around the Symbology Object but I cannot access the colors of each Unique Value Symbol.

This is how I am accessing the the Symbology of the individual layers. There doesn't seem to be and option to change the color a value.

  • I am using ArcGIS 10.2.1

    mxd_file = r"some\path\file.mxd"
    mxd = arcpy.mapping.MapDocument(mxd_file)
    
    # getting data frame   
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    
    # getting street layer
    street_layer = arcpy.mapping.ListLayers(mxd, 'Street', df)[0]
    
    if street_layer.symbologyType == 'UNIQUE_VALUES':
        # trying to access all possible properties of the symbology object
        street_symbology = street_layer.symbology
        desc = street_symbology.classDescription
        labels = street_symbology.classLabels
        values = street_symbology.classValues
        show_other_values = street_symbology.showOtherValues
        value_field = street_symbology.valueField
    del mxd, df
    
    layer_file = r"some\path\file.lyr"
    arcpy.SaveToLayerFile_management(path_layer, layer_file)
    
0

3 Answers 3

2

I agree with the comment by @Hornbydd:

The short answer is no. The only way I am aware using the standard geo-processing tools is to use the Apply Symbology From Layer tool. It may be possible to access the Symbology using python to drive ArcObjects, you would have to do some research on that.

1

Example of using Apply Symbology From Layer tool with Python. Start by defining symbology for the first layer in map and then use this to set symbology of all other layers:

import arcpy
mxd=arcpy.mapping.MapDocument("CURRENT")
lyrlist=[f.name for f in arcpy.mapping.ListLayers(mxd)]
lyrlist=lyrlist[1:] #exclude the first layer
for lyr in lyrlist:
    arcpy.ApplySymbologyFromLayer_management(lyr,"templateSymbologyLayer") 
0

Current answer for ArcMAP 10.8 (may be some previous versions too) is "yes, it's possible". You can use a Layer method .updateLayerFromJSON

Core part of solution is to create JSON description of layer symbology.

Code sample:

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "name*")[0]
lyr.updateLayerFromJSON(json_dictionary)

There is a valid example for polygon layer with single symbol symbology.

{"name": "pointLayer",
"geometryType": "esriGeometryPolygon",
"drawingInfo": {
        "renderer":{
        "type": "simple",
        "symbol": {
        "type": "esriSFS",
        "style": "esriSFSSolid",
        "color": [           76,           115,           0,           255          ],
        "outline": {
        "color": [            255,            0,            0,            255           ],
        "width": 1          }}}}}

Above code is a value of tag layerDefinition from this specification: https://enterprise.arcgis.com/ru/server/10.8/create-web-apps/windows/exportwebmap-specification.htm#ESRI_SECTION1_FC212A2B579B425A9FE4358ACC89482A

Details about specification can be found here: https://developers.arcgis.com/web-map-specification/objects/renderer/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.