5

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

  • 1
    See the Q&A here as there is a very simple way of doing this. – Hornbydd Nov 5 '15 at 17:10
  • 2
    @Hornbydd, yeah, that's a bit easier! The linked one should probably be closed (merged) and you can post your answer here. – Paul Nov 5 '15 at 17:28
  • @Paul, I don't know, I liked your code that will be useful to others (including me) and it is a solution... Mine is just simpler! ;) Also what did you use to record that moving image? – Hornbydd Nov 5 '15 at 17:42
  • 1
    @Hornbydd, I wrote a .bat file based off this blog (it's just a few calls to ffmpeg). Drag a video file onto it and choose start and/or ending times. You can use any recording software, but I'm using Snagit. – Paul Nov 5 '15 at 17:48
7

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

  • do you know how to do this in ArcGIS Pro? When I try and use trunclabels I get the following error: AttributeError: module 'arcpy.mp' has no attribute 'ListDataFrames' – Matt A. Dec 15 '17 at 16:44
  • @MattA. Pro doesn't have the concept of data frames. You would instead list maps. See here for more info. – Paul Dec 20 '17 at 16:50

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.