Saturday 23 May 2015

arcpy - ApplySymbologyFromLayer_management sets polygon outlines to default


I'm struggling with an issue which I think is a bug in arcpy. I am 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 what 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?



Answer



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.




ESRI was right, the bug is fixed!


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...