0

I can't seem to figure out or find a work around for the symbology labels after a reclassify when trying to automate maps. I run the following code and it is almost doing exactly what i want it to do. After I change a data source path I run the following 2 lines of code. The layer is set to have the colors i want and the numbers match what should be there. The only issue is the display of the labels for the classification.

                arcpy.mapping.UpdateLayer(df, lyr, updateLayer, True) 
                lyr.symbology.reclassify() 

The map is set to have 1 decimal place as is the layer file but after the reclass it is set to 4 significant digits.

enter image description here

Does anyone have any thoughts?

This is the one thing i need to fully automate the maps i am working on. It seems crazy that after doing a change path and a reclass that i have to open the mxd reset the layer properties and then update notes that i have generated based on the new classes with the update ranges.

2 Answers 2

1

I think you're expecting too much from 'reclassify'; rather you should be doing a manual classification, or apply this sample code below (untested) to refresh based on specific 'breaks' which of course you define:

# from GraduatedColorsSymbology example 2 in web help    
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Census")[0]
lyr = arcpy.mapping.ListLayers(mxd, "StatePopulation", df)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\LYRs\Population.lyr")
arcpy.mapping.UpdateLayer(df, lyr, lyrFile, True)
if lyr.symbologyType == "GRADUATED_COLORS":
  lyr.symbology.valueField = "POP2000"
  lyr.symbology.classBreakValues = [250000, 999999, 4999999, 9999999, 35000000]
  lyr.symbology.classBreakLabels = ["250,000 to 999,999", "1,000,000 to 4,999,999", 
                                        "5,000,000 to 9,999,999", "10,000,000 to 35,000,000"]
arcpy.mapping.ExportToPDF(mxd, r"C:\Project\Output\StatePopulation.pdf")
del mxd, lyrFile
5
  • Thank you for the response I don't think i am asking too much at all. It seems totally reasonable to expect or be able to classify with 1 decimal place if i started with 1 decimal place. Also I don't know the ranges until after it is reclassified the data is floating point and changes month to month. I know i can set the ranges manually but that defeats the purpose of the reclass for what i am doing.
    – Matt
    Mar 26, 2015 at 18:39
  • Thought that's where you were heading but wanted to be sure...very well. So in that case, I'm not logged in to confirm, but can you intercept from the layer object the reclassification values and subsequently apply similar logic as from the sample code to 'reapply' rounded output? Mar 26, 2015 at 19:51
  • Just checked the webhelp-- classBreakLabels are both read/write as a list, so you should be able to read the labels in, reformat the labels to reflect the rounded to 10ths you desire, then write the list back to that property...and refresh the layer. Mar 26, 2015 at 20:05
  • I actually had just figured it out.
    – Matt
    Mar 26, 2015 at 20:15
  • See below for my solution to build the legend.
    – Matt
    Mar 26, 2015 at 20:21
0

I fixed the problem by building the range myself as suggested. It just came to me!

Here is the solution. you can add lower range to set the labels as suggested by T. Wayne or just use the range for a some notes i needed to create on the map.

lower_range1 =  "{:.1f}".format(lyr.symbology.classBreakValues[0]) + " - " + "{:.1f}".format(lyr.symbology.classBreakValues[1])

lower_range2 =   "{:.1f}".format(lyr.symbology.classBreakValues[1] + .1) + " - " + "{:.1f}".format(lyr.symbology.classBreakValues[2])

lower_range3 =   "{:.1f}".format(lyr.symbology.classBreakValues[2] + .1) + " - " + "{:.1f}".format(lyr.symbology.classBreakValues[3])

lower_range4 =   "{:.1f}".format(lyr.symbology.classBreakValues[3] + .1) + " - " + "{:.1f}".format(lyr.symbology.classBreakValues[4]) 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.