Vary symbology by rotation using ArcPy

263
4
12-10-2022 07:13 PM
Status: Under Consideration
Labels (1)
Bud
by
Frequent Contributor

Edited

When creating feature layers using ArcPy:

There doesn’t seem to be a way to Vary symbology by rotation using ArcPy.

Could that functionality be added?

Related: ArcPy script to convert layer to individual feature layers for each symbology class
https://community.esri.com/t5/arcgis-pro-sdk-questions/customize-pro-ui-checkboxes-in-toc-to-toggle/...

Tags (2)
4 Comments
DanPatterson

Symbol—ArcGIS Pro | Documentation

angle
(Read and Write)
Gets and sets the rotation value of a point symbol.

Double

JohannesLindner

The question is a bit unclear.

Yes, there is symbol.angle, but that sets the angle value of each symbol.

What @Bud means is that there is no way in arcpy to Vary symbology by rotation—ArcGIS Pro | Documentation

 

JeffBarrette
Status changed to: Under Consideration

This is something we can consider but it will be a long time before we can provide this level of detail via the curated API. In the meantime, the CIM may be an option.  Before reviewing the code below it may be worth reviewing the Python CIM Access help topic: 

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm

I started with:

BEFORE_UI.PNG

As suggested in the topic above, I created a before and after layer, saved them to LYRX files and compared the JSON differences.

JSON_Difference.PNG

Here is the code based on what I see above.  The before layer didn't have visual variable applied so I had to create the appropriate CIM objects, set the values to match above and then apply the newly created visual variable to the empty visual variable list associated with the layer.

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
l = m.listLayers('*BEFORE')[0]
maxLabel = 360 #this could be automated

#Create a rotation visual variable via the CIM
l_cim = l.getDefinition('V3')
visVar = arcpy.cim.CreateCIMObjectFromClassName('CIMRotationVisualVariable', 'V3')
#Xinfo
visVar.visualVariableInfoX.randomMax = maxLabel
visVar.visualVariableInfoX.visualVariableInfoType = "None"
#Yinfo
visVar.visualVariableInfoY.randomMax = maxLabel
visVar.visualVariableInfoY.visualVariableInfoType = "None"
#Zinfo
visVar.visualVariableInfoZ.randomMax = maxLabel
visVar.visualVariableInfoZ.visualVariableInfoType = "Expression"
#Create expression for Xinfo
expInf = arcpy.cim.CreateCIMObjectFromClassName('CIMExpressionInfo', 'V3')
expInf.title = "Custom"
expInf.expression = "$feature.Rotation"  #field called rotation
expInf.returnType = "Default"

visVar.visualVariableInfoZ.valueExpressionInfo = expInf
visVar.rotationTypeZ = "Arithmetic"

l_cim.renderer.visualVariables.append(visVar) #Apply visual variable
l.setDefinition(l_cim) #set back to layer

 

And the final result:

AFTER_UI.PNG

I hope this helps,

Jeff - Layout and arcpy.mp teams

JohannesLindner

Thanks Jeff, that helps alot.

I have done some work with the CIM (especially configuring popups), but I haven't looked too far into it regarding symbology.