I have an ETL updating a layer attribute on a registered Enterprise geodatabase. The layer has been published on ArcGIS Portal which sends the layer with updated values to ArcGIS Online. This data is on a webmap that has Natural Breaks symbology applied to it. The web map participates on a web site. The layer is updated twice a day.
When the data values exceed the maximum value from the previous update the symbology can't render those now out of range values requiring someone to open the webmap and reapply the symbology each time the ETL runs.
Currently I'm using selenium to mimick a user logging on and doing the update manually but it is hacky and often errors out. Also requires an active user profile session on console machine.
I looked into Python API for ArcGIS and came across this: https://community.esri.com/groups/arcgis-python-api/blog/2019/04/09/updating-layer-symbology-with-the-arcgis-api-for-python
but it looks like that only works if you already have the values for your breaks defined in an existing JSON file you use to update the current JSON file your web map is referencing.
Last, I tried to use arcpy to update symbology in an ArcPr project and export the layer file and get the new JSON values from that, but applying the code below did not update anything:
import arcpy
p = arcpy.mp.ArcGISProject(r'C:\my_project.aprx')
m = p.listMaps()[0]
for lyr in m.listLayers():
if lyr.isFeatureLayer:
sym = lyr.symbology
if hasattr(sym, 'renderer'):
sym.updateRenderer('GraduatedColorsRenderer')
sym.renderer.classificationField = 'CaseRates'
sym.renderer.classificationMethod = 'NaturalBreaks'
sym.renderer.breakCount = 5
lyr.symbology = sym
Seems like this should be way more simple than this, especially as this does not work.