[GIS] Layers not appearing when updated with UpdateLayer in arcpy

arcgis-10.0arcpylayers

I have a script that calculates kernel density for several sets of points, adds the output to a base map, updates the added layer to use the same color scheme and resampling function of a template layer, then zooms to the extent of the new layer.

This works fine for some of the resulting maps; the density output shows on the map, the color is as it should be, and it is sampled using bilinear interpolation as I wanted. The problem is that most of the resulting maps do not show the kernel output at all; only the basemap is visible.

I have isolated the code I am using and have altered it to compute one simple test case. Here is what I have:

SubjectLyr = arcpy.mapping.Layer(r"F:\\testFiles\\output\\Population23_KDens.lyr")
mxd = arcpy.mapping.MapDocument("F:\\testFiles\\testMap.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0] 
wPath = "F:\\testFiles\\output\\" # same as in line 1

#Add the layer to basemap
arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") 

#Update the layer
SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df)[0] # change reference to layer in mxd
sourceLayer = arcpy.mapping.Layer(wPath+"templates\\template.lyr") # get template layer
arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True)

###Zoom to selection
df.zoomToSelectedFeatures()
lyrExtent = SubjectLyr.getSelectedExtent()
df.extent = lyrExtent
arcpy.mapping.ExportToPDF(mxd, r"F:\\testFiles\\output\\Population23_KDens_Map.pdf")
print('DONE!')

I have read that there is some existing issue with UpdateLayer in ArcMap 10.1, though I am using 10.0. As shown, my code is practically identical to the code that is a "workaround" to this problem described in the above linked forum. This code works for some, but not all of my datasets.

I have also tried using the ApplySymbologyFromLayer_management() function, which does make all the kdens output layers appera; however, this does not change the resampling function used when drawing the output, and I need to to use bilinear interpolation.

Does anyone know what could be going on? Are there any other functions I could use?

Best Answer

I finally figured out the problem, and I feel decidedly silly for not thinking of it before.

My template layer, from which the symbology was being taken in UpdateLayer, was using the "classified" symbology method with "no color" for values falling between 0 and 104. The default kernel density output uses the "stretched" symbol, and when being forced into the "classified" scheme, many of the values fell within the "no color" range. As a result, the density output from many of my datasets did not show up at all.

Now after changing the template layer to the "stretched" symbology scheme and using UpdateLayer again, everything works fine!

Related Question