Sunday, 28 August 2016

arcgis desktop - How to change the number of decimal digits in arcmap in symbology


I'm using ArcMap 10.3. In symbology, there are 6 decimal digits for the different classes of the variable I'm presenting. I'd like to show only 3 decimal digits. I can edit the label and change the decimals manually for each class. Is there any faster way to do this for all classes in ArcMap 10.3?enter image description here



Answer




You can accomplish this with the arcpy.mapping module. The following should work as long as your symbology is GraduatedColorsSymbology. Just paste into the python window and run the function with your layer name and number of decimal places. Since it's using Python's built-in round() function, you can even use negative numbers.


def trunclabels(lyrname, n):

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, lyrname, df)[0]

labels = lyr.symbology.classBreakLabels
#split the labels, cast to float, round, then join back together
lyr.symbology.classBreakLabels = ["{} - {}".format(*r)

for r in [[round(float(f), n)
for f in lab.split(" - ")]
for lab in labels]]

arcpy.RefreshTOC()
del mxd, df

enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...