1

I have a script that iterates through a folder of jpgs, clips them to a grid, inserts them to an mxd, and exports them. My original problem was when I added the clipped raster from a standalone script to my mxd, it would automatically render it as a 1 band stretched image when a 3 band RGB is desired. In the python window I was able to use copy raster (management) with the "ColormapToRGB" parameter to create a layer that was displayed correctly. The problem now is when I run it from a standalone it doesn't automatically add the RGB to my TOC like it did from the python window. I instead have to add the RGB with another line like I did with my original clipped raster and I run into the same 1 band rendering issue. Anyone one know how I can get the RGB image to appear in my TOC with the correct display?

import arcpy

#Define workspaces
arcpy.env.workspace = "C:\\FolderPath" 
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("C:\\FilePath.mxd")

#Define layer locations
df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
quads = "C:\\Geodatabase.gdb\\Quads_14"
qSelect = "C:\Geodatabase.gdb\qSelect"
outRast = "C:\\Geodatabase.gdb\\rastClip"

#Slice strings for SelectLayerByAttribute
qname = path[12:-4].replace("_", " ")
qnameUp = qname.upper()
sqlString = "NAME LIKE" + " '" + qnameUp + "'"

#Inserts each JPEG in folder and does all geoprocessing/map labelling/exporting
for jpg in arcpy.ListRasters("2*","JPG"):
    arcpy.MakeFeatureLayer_management(quads, qSelect, sqlString)
    desc = arcpy.Describe(qSelect)
    extent = str(desc.extent)
    arcpy.Clip_management(in_raster=jpg, rectangle=extent, out_raster=outRast, in_template_dataset=qSelect, nodata_value="256",clipping_geometry="ClippingGeometry", maintain_clipping_extent="NO_MAINTAIN_EXTENT")
    topo = arcpy.mapping.Layer(outRast)
    arcpy.mapping.AddLayer(df, topo, "TOP")
    arcpy.CopyRaster_management(outRast, out_rasterdataset="C:/FilePath", nodata_value="256", onebit_to_eightbit="NONE",colormap_to_RGB="ColormapToRGB", scale_pixel_value="NONE", RGB_to_Colormap="NONE")

arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.save()
del mxd, df

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.