AnsweredAssumed Answered

arcpy.mapping.UpdateLayer vs arcpy.ApplySymbologyFromLayer

Question asked by drc_ on Feb 5, 2013
Latest reply on Feb 6, 2013 by drc_
I want to change the symbology of a raster so that it matches a .lyr file I have stashed away. Once the symbology is set I will read the classBreakValues and build a RemapRange so that I can reclassify the raster cell values using Reclassify.

I would prefer to do this via arcpy.ApplySymbologyFromLayer because it allows me to work outside of an MXD. The problem is that it doesn't seem to apply the symbology correctly. My .lyr file symbology uses the Standard Deviation classification method with 3 classes but when I run ApplySymbologyFromLayer the result always has 4 classes, even when I apply the symbology to the original source raster I used to create the .lyr file. Attempting to set the numClasses = 3 after applying the symbology doesn't work.

Conversely, arcpy.mapping.UpdateLayer applies the symbology correctly but requires an mxd and dataframe as input parameters. I want to minimize file dependencies and would prefer not to have dummy .mxd's laying around, which is what I need in order to use UpdateLayer.

So, why does a single .lyr file produce two different results when applied to the same dataset via UpdateLayer and ApplySymbologyFromLayer?

This script will be used by many users on many different rasters and I really, really, really, don't want to have dummy .mxd's stashed around our network. Is there any way to avoid this? I would prefer not to have a file dependency on the .lyr file either; does anyone see a way around that? Shouldn't there be a classificationMethod property so I can do something like:

layer.symbology.classificationMethod = standard_deviation
layer.symbology.numClasses = 3