Arcpy.mapping.UpdateLayer() doesn't apply visualization options?

2944
0
02-03-2015 08:06 AM
JoseEduardo_Moyano_Capilla
New Contributor

Hi all,

I am trying to create a time series animation automatically from NetCDF files, containing each file monthly data for the whole planet for periods of 10 years. I am writing a python script that reads the file for each time step and creates a bmp image for each time step. I use a layer as a template with the symbology that I want to be applied in the images. I collect all the images in the same workspace and then I use the convert raster to video tool. Everything works fine, but I just realized that I have a problem when I want the user to select an extent to visualize the animation (subregions, countries...). The layer template has stretched symbology with the option "current display extent" selected, as I want to use a different range of values in each extent (to improve visualization). When I change the view extent directly in ArcMap it works fine. Even if I use python code in the PythonWin. But when I run the script, it takes the symbology from the template but doesn't apply the "current display extent", but the by default "each raster dataset" option, which gives me very poor visualization in extents at a very large scale.

There is a funny thing. To check how the script works, I saved a copy of all the layers used in the process (a layer for every time step) in a mxd document. When I open that mxd, the layers are shown with the "current display extent", that's what I want to get, but in the video and the images created automatically the visualization is different! Why is that? Am I doing something wrong? Someone has any experience on this? I hope I explained myself, as it's a little bit mess.

Below is the main part of the code, if it helps. Please note that there are some parts missing.

Thanks in advance!!

mxd = arcpy.mapping.MapDocument(template)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
sourceLayer = arcpy.mapping.ListLayers(mxd,"Dis_Layer4",df)[0]
sourceLayer.visible = False

extent = arcpy.GetParameterAsText(2)
bkmk = arcpy.mapping.ListBookmarks(mxd, extent)[0]
df.extent = bkmk.extent
legend = arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT", "Legend")[0]
styleItem = arcpy.mapping.ListStyleItems('P:\\HRRD\\WR_Section\\GWAVA\\Visualisation\\data\\josmoy.style',"Legend Items","discharge")[0]

while date <= datefin:
        dimensionValues = "Time " + date.strftime("%d/%m/%Y")
        outRasterLayer = "Discharge"

        #Creates a raster layer for the specific time step.
        arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, variable, XDimension, YDimension,
                           outRasterLayer, bandDimmension, dimensionValues,
                           "BY_VALUE")

        #Add the new layer and take the symbology from the template layer
        AddLayer = arcpy.mapping.Layer(outRasterLayer)
        arcpy.mapping.AddLayer(df,AddLayer)
        lyr = arcpy.mapping.ListLayers(mxd, AddLayer, df)[0]
        arcpy.mapping.UpdateLayer(df,lyr,sourceLayer,True)
        legend.updateItem(lyr,styleItem)

        arcpy.RefreshActiveView()
0 Kudos
0 Replies