Select to view content in your preferred language

Arcpy code to remove decimal digits in symbology (ArcGIS Pro)

1273
4
Jump to solution
12-15-2017 08:58 AM
Business_IntelligenceSoftware
Occasional Contributor

Whenever I perform the Summarize Within tool in ArcGIS Pro and use the graduated colors symbology on the resulting feature class, I end up with something that looks like this:

Is there a way to remove all those zeros? In other words can I set the results to zero decimal places using Arcpy for ArcGIS Pro?

0 Kudos
1 Solution

Accepted Solutions
Business_IntelligenceSoftware
Occasional Contributor

I used the following code to get the results I was looking for:

p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps()[0]
lyr = m.listLayers("layer_name")[0]
sym = lyr.symbology
if sym.renderer == "GraduatedColorsRenderer":
    breaks = sym.renderer.classBreaks
    for b in breaks:
        b_int = b.label[0:-7]
        b.label = b_int
lyr.symbology= sym

View solution in original post

4 Replies
DanPatterson_Retired
MVP Emeritus

You can begin within the ClassBreak section.  I don't know how far down you can burrow to find out if they can be set to an integer value. I don't know how far along you have gotten.  Is there a need to use python and arcpy for this?

0 Kudos
Business_IntelligenceSoftware
Occasional Contributor

Yes I need to use arcpy because I want to implement it into a larger script

0 Kudos
DanPatterson_Retired
MVP Emeritus

http://pro.arcgis.com/en/pro-app/arcpy/mapping/classbreak-class.htm but according to the code sample you have to format the labels yourself, which can be done using standard python formatting with the appropriate decimal specifier

a = 10000.0
"{:2.0f}".format(a)  # '10000'
"{:2.1f}".format(a)  # '10000.0'
"{:2.2f}".format(a)  # '10000.00'
Business_IntelligenceSoftware
Occasional Contributor

I used the following code to get the results I was looking for:

p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps()[0]
lyr = m.listLayers("layer_name")[0]
sym = lyr.symbology
if sym.renderer == "GraduatedColorsRenderer":
    breaks = sym.renderer.classBreaks
    for b in breaks:
        b_int = b.label[0:-7]
        b.label = b_int
lyr.symbology= sym