Hello!
I am trying to update the symbology of a raste layer using an existing layer file with 2 different functions:
- update layer
- apply symbology from layer
The same function works with shapefiles, though.
Nothing happens, still the code runs till the end with no error message, which makes it pretty difficult to find the error.
<SPAN class="keyword token">import</SPAN> arcpy
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
workDir <SPAN class="operator token">=</SPAN> <SPAN class="string token">'C:/0.STUDY PROJECT/Maps/'</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>template<SPAN class="punctuation token">)</SPAN>
dfs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN>
df <SPAN class="operator token">=</SPAN> dfs<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># clip is obtained interpolating a point shapefile with natural neighbours method and clipped with a polygon shapefile</SPAN>
clip <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\0.STUDY PROJECT\\MapsKulmbach\\processed_data\\clip"</SPAN>
depth_data <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">(</SPAN>clip<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>AddLayer<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> depth_data<SPAN class="punctuation token">)</SPAN>
srcLay <SPAN class="operator token">=</SPAN> workDir <SPAN class="operator token">+</SPAN> <SPAN class="string token">"depthSymbology.lyr"</SPAN>
srcLayObj <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">(</SPAN>srcLay<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># try function 1</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>UpdateLayer<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> depth_data<SPAN class="punctuation token">,</SPAN> srcLayObj<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># try function 2</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ApplySymbologyFromLayer_management <SPAN class="punctuation token">(</SPAN>depth_data<SPAN class="punctuation token">,</SPAN> srcLayObj<SPAN class="punctuation token">)</SPAN>
mxd<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Do you know what a reason could be?
Thank you