1

Is it possible to set a raster symbology to unique values using arcpy.mapping.UpdateLayer. Using 10.3 I am receiving an AssertionError

import sys, os, arcpy
sourceLayer = r'D:\Chad\GIS\TEMP\raster_unq_val.lyr'
mxd = arcpy.mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
lyr = arcpy.mapping.ListLayers(mxd, "MapunitRaster_fy16_10m", df)[0]

print lyr.name
print lyr.symbologyType
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer, True)
desc = arcpy.Describe(lyr)
flds = [x.name for x in desc.fields]
for f in flds:
    if f.find('rating') <> -1:
        targetField = f

values = list()

with arcpy.da.SearchCursor(lyr, targetField) as rows:
    for row in rows:
        aVal = round(row[0], 2)
        if not aVal in values:
            values.append(aVal)
values.sort()

lyr.symbology.valueField = targetField
lyr.symbology.addAllValues()
lyr.symbology.classValues = values
lyr.symbology.classDescriptions = values
lyr.symbology.ShowOtherValues = False

arcpy.RefreshActiveView()
arcpy.RefreshTOC()

del values

with the error:

Runtime error Traceback (most recent call last): File "", line 9, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\mapping.py", line 1889, in UpdateLayer assert isinstance(source_layer, Layer) AssertionError

closed as off-topic by PolyGeo Jan 9 '17 at 9:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Have you tried changing source_layer to a Layer object? sourceLayer = arcpy.mapping.Layer(r'D:\Chad\GIS\TEMP\raster_unq_val.lyr') – Paul Sep 22 '16 at 15:58
  • 1
    @Paul you should add that as an aswer – Midavalo Sep 22 '16 at 22:59

Browse other questions tagged or ask your own question.