Select to view content in your preferred language

Change Alpha channel on multiple ecw tiles

883
4
Jump to solution
08-21-2013 04:37 AM
ScottClune
Emerging Contributor
Hi All,

Trying to save myself hours of work here, I have a layer with >300 ecw tiles from aerial photography all of which need the alpha channel updated to be band 4.

Is there a way to achieve this using python, if so what functions should I be looking at to change these attributes.

I have not done anything in python but have experience in vb.net and SQL. So am hoping to add python to my bag of tricks.

Any code examples or hints will be greatly appreciated.

Cheers

Scott
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisPedrezuela
Frequent Contributor
I've tried it like this, and its fine,
import arcpy  mxd = arcpy.mapping.MapDocument(mxd_path) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]  sourceLayer = arcpy.mapping.Layer(layerfile_path)  for lyr in arcpy.mapping.ListLayers(mxd,'',df):     if lyr.isRasterLayer == True:         arcpy.mapping.UpdateLayer(df, lyr, sourceLayer, True)         print lyr.name  mxd.saveACopy(r"E:\Test2.mxd")  del lyr, mxd

View solution in original post

0 Kudos
4 Replies
ChrisPedrezuela
Frequent Contributor
Hi Scott,

Why not just create a LYR file from a raster with the alpha band already set and then create a short script to updated the other raster layers in your mxd. Look up this fucntion, "UpdateLayer (arcpy.mapping)".

Cheers,
0 Kudos
ScottClune
Emerging Contributor
Thanks Thanos,

I have looked at arcpy.mapping.UpdateLayer and it looks as though it will achieve what I want it to do..

using the example shown in the help I have created an mxd for testing with all the ecw files in it.
I then created a lyr file with one ecw file with the alpha channel changes implemented.

I called the layers in my files updateLayer and sourceLayer to avoid confusion.

Below is my code..

import arcpy
mxd = arcpy.mapping.MapDocument(r"E:\Scott Created GIS Files\MXDs\UpdateImagery2.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "updateLayer", df)[0]
sourceLayer = arcpy.mapping.Layer(r"E:\Scott Created GIS Files\MXDs\sourceLayer.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
mxd.saveACopy(r"E:\Scott Created GIS Files\MXDs\UpdateImagery_3.mxd")


When I try t run this script in pythonwin I get a rather unhelpful error  "ValueError: LayerObject: Unexpected error"

could this possibly be a security issue with windows 7 allowing python access to the file?

I have googled the error but have not found any helpful information, have you seen this before with this function.?

any help would be great.

Cheers
0 Kudos
ChrisPedrezuela
Frequent Contributor
I've tried it like this, and its fine,
import arcpy  mxd = arcpy.mapping.MapDocument(mxd_path) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]  sourceLayer = arcpy.mapping.Layer(layerfile_path)  for lyr in arcpy.mapping.ListLayers(mxd,'',df):     if lyr.isRasterLayer == True:         arcpy.mapping.UpdateLayer(df, lyr, sourceLayer, True)         print lyr.name  mxd.saveACopy(r"E:\Test2.mxd")  del lyr, mxd
0 Kudos
ScottClune
Emerging Contributor
Thanks Theros,

I realised after my last post that I was trying to update a group layer rather than a raster layer.

and when I removed the group layer the original code worked after I added in the loop through the raster layers..

Thanks very much for your assistance.

it has been much appreciated and I hope I can repay the favour one day.

Cheers:)
0 Kudos