Hi all, I am trying to add a TIF file as an ArcGIS Pro map layer and apply symbology from a .lyrx file. If I manually drag a TIF file onto the map and import the .lyrx file, it draws just fine. These data layers are dynamic, so I want to automate adding many of these TIF files and symbolizing them via python. I found 2 different ways to use python to add a TIF file as a new map layer, but I'm stuck on applying the .lyrx file.
With either approach, I then use arcpy.ApplySymbologyFromLayer_management to try to set the symbology. I never get a python error, but it doesn't have any effect. The new layer is just there with the default stretched black-to-white color ramp.
datapath <SPAN class="operator token">=</SPAN> <SPAN class="string token">'C:\\temp'</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN>
m <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># approach 1 - creates a layer with a name I assign</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeRasterLayer_management<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>datapath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wrfout_d3.2015081400.f13.0000.UV10.tif'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'f13'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token"><</SPAN>Result <SPAN class="string token">'f13'</SPAN><SPAN class="operator token">></SPAN>
asfl <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ApplySymbologyFromLayer_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'f13'</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>datapath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wind_barbs_uv.lyrx'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
asfl
<SPAN class="operator token"><</SPAN>Result <SPAN class="string token">'f13'</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="comment token"># approach 2 - creates a layer with the same name as the TIF</SPAN>
lyr <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">.</SPAN>addDataFromPath<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>datapath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wrfout_d3.2015081400.f13.0000.UV10.tif'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
asfl2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ApplySymbologyFromLayer_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'wrfout_d3.2015081400.f13.0000.UV10.tif'</SPAN><SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>datapath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wind_barbs_uv.lyrx'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
asfl2
<SPAN class="operator token"><</SPAN>Result <SPAN class="string token">'wrfout_d3.2015081400.f13.0000.UV10.tif'</SPAN><SPAN class="operator 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>
Possibly relevant details:
- I am using the "Vector Field" symbology type
- The TIF has 2 bands for the U and the V direction components (these are set in .lyrx file)
- I also tried plugging the default band names ("Band_1" & "Band_2") into the "symbology_fields" parameter of the ApplySymbologyFromLayer_management function. It also had no effect.
- Updated from 2.1.2 to 2.1.3 with the same result.
I'm not sure if I'm doing the wrong thing or missing a step. In the help, it shows ApplySymbologyFromLayer_management being used to apply symbology to another layer file, so I'm guessing it's not meant to applied to a map layer, but I don't know where to go from there.
Thanks!