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 = 'C:\\temp'
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()
# approach 1 - creates a layer with a name I assign
arcpy.MakeRasterLayer_management(os.path.join(datapath, 'wrfout_d3.2015081400.f13.0000.UV10.tif'), 'f13')
asfl = arcpy.ApplySymbologyFromLayer_management('f13', os.path.join(datapath, 'wind_barbs_uv.lyrx'))
# approach 2 - creates a layer with the same name as the TIF
lyr = m.addDataFromPath(os.path.join(datapath, 'wrfout_d3.2015081400.f13.0000.UV10.tif'))
asfl2 = arcpy.ApplySymbologyFromLayer_management('wrfout_d3.2015081400.f13.0000.UV10.tif', os.path.join(datapath, 'wind_barbs_uv.lyrx'))
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.