ApplySymbologyFromLayer_management sets polygon outlines to default

752
3
10-20-2016 02:02 AM
RahelKreutz
New Contributor

Hi all,

I'm struggling with an issue which I think is a bug in arcpy. I'm using AddSymbologyFromLayer_management to apply the symbology from a reference layerfile (yes, an actual layerFILE, not a layer within the mxd) to a newly created polygon shapefile which is displayed as a layer. This works fine, even when I change the field the symbology  shall be based on. However, when I also change the class breaks (I use GRADUATED_COLORS here), the outlines, which are set to "No color" in the reference layerfile, are set back to default, which means some kind of grey with 0.4pt width. This behaviour only occurs when I change the class breaks via code, if I keep them as they are, everything is fine.

This is what I basically do within the code:

# get reference layer
ref_lyr_file = os.path.join(workspace, 'styles', 'graduated_colors_reference_style.lyr')
# get newly created layer
new_lyr = arcpy.mapping.ListLayers(mxd, lyr, mapDF)[0]
# import symbology from reference layer-file
arcpy.ApplySymbologyFromLayer_management(new_lyr, ref_lyr_file)
# set value field
new_lyr.symbology.valueField = draw_param_dict[draw_parameter]
# reclassify values
new_lyr.symbology.reclassify()
breaks = new_lyr.symbology.classBreakValues
# round values nicely as new class breaks
lenMin = len(str(int(breaks[1])))
new_breaks = [int((round(b / (10 ** lenMin), 2)) * (10 ** lenMin)) for b in breaks]
# update map document
new_lyr.symbology.classBreakValues = new_breaks
arcpy.RefreshTOC()
arcpy.RefreshActiveView()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

How I create the new breaks is not important, so you can skip this section. The thing is: the polygon outlines are set back to the default color ONLY AFTER applying new class break values.

Does anyone know how to get around this?

Thanks for any help

0 Kudos
3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

there is this little strange statement in here Merge—Data Management toolbox | ArcGIS for Desktop which I am not sure what it actually does, but it is worth a look, since there is nothing specific in arcpy anything for setting the outline style

Updating the symbology of the layer in the map document with the symbology stored in the layer file may produce unintended results (for example, the class break values will match the layer file's data source statistics as opposed to the map document layer's data source statistics. However, if you follow UpdateLayer with the reclassify() method, the end result is like using the color properties from the symbology in the layer file, but other characteristics are based on the map document layer's underlying source data.

0 Kudos
RahelKreutz
New Contributor

Hi Dan,

you're right, you can not set the outline of polygons using arcpy (a major, issue, from my point of view). It is also correct that the initial class break values rely on the reference layer unless you call the reclassify-method. However, the behaviour I'm struggling with occurs whether I use UpdateLayer or ApplySymbologyFromLayer. I think it is a general problem with arcpy, and even the ESRI-folks have not found a probable solution so far.

0 Kudos
RahelKreutz
New Contributor

I've been communicating back and forth with ESRI and they finally came up with an answer: it seems to be a bug in the arcpy API, which shall be fixed with ArcGIS 10.5 (pre-release already available). As soon as I can confirm this, I will post it here. From what ESRI told me, there is no workaround for versions lower than 10.5 except for manual adjustment.

0 Kudos