Runscript Error - line 312???

717
7
04-30-2012 01:42 PM
MikeBly
Occasional Contributor
Anyone know why I get this error in my traceback: The first and last errors - I cannot find any documentation on.

Any ideas would be greatly appreciated. This is a very simple script to rename a batch of raster files.

Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript
    exec codeObject in __main__.__dict__
  File "G:\Documentation\Python_Scripts\batchCopyRaster_COL.py", line 32, in <module>
    arcpy.CopyRaster_management(input,output)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 6835, in CopyRaster
    raise e
ExecuteError: Failed to execute. Parameters are not valid.

Thanks
Tags (2)
0 Kudos
7 Replies
MathewCoyle
Frequent Contributor
Have you checked to make sure the files and folders exist, have valid names etc?
0 Kudos
DarrenWiens2
MVP Honored Contributor
Sorry to say it, but I'd guess the parameters are not valid (either "input" or "output"), but you'd have to post the code for anyone to figure it out.
0 Kudos
MikeBly
Occasional Contributor
Have you checked to make sure the files and folders exist, have valid names etc?


All the files and folders look correct, and the script references the proper locations, ???

Thanks,

Mike
0 Kudos
MikeBly
Occasional Contributor
Sorry to say it, but I'd guess the parameters are not valid (either "input" or "output"), but you'd have to post the code for anyone to figure it out.


Here is the super simple code - I must be missing something obvious - be kind I am a newbie to scripting...


# Import system modules
import arcpy

#Set working directory

arcpy.env.workspace = "G:\Imagery\Orthos_2009\Photos\TIFF"

# Define Input and Output folder

InFolder = "G:\Imagery\Orthos_2009\Photos\TIFF"
OutFolder = "G:\Imagery\Orthos_2009\Photos\TIFF_Renamed"

# Create List of Rasters in Folder

rasterList = arcpy.ListRasters()

# Loop Through Folder renaming rasters and save in new folder

for raster in rasterList:
  print("Beginning Copy of " + raster)
  input = InFolder + "/" + raster
  output = OutFolder + "/nn" + raster
#Copy Rasters
  arcpy.CopyRaster_management(input,output)
  print(" Copy of " + raster + " complete." + "\n")
  rasterList.next()

del arcpy


Any thoughts here, thanks for the help,

Cheers,

Mike
0 Kudos
MathewCoyle
Frequent Contributor
Your paths are incorrect. Valid path formats are as follows.

arcpy.env.workspace = r"G:\Imagery\Orthos_2009\Photos\TIFF"
arcpy.env.workspace = "G:\\Imagery\\Orthos_2009\\Photos\\TIFF"
arcpy.env.workspace = "G:/Imagery/Orthos_200/Photos/TIFF"


The proper way to combine a path and file name are as follows. Both of these require importing the os module
input = os.path.join(InFolder,raster) # Much preferred
input = InFolder + os.sep + raster
0 Kudos
MikeBly
Occasional Contributor
Have you checked to make sure the files and folders exist, have valid names etc?


Thanks for this - got me thinking about supported file types with the Copy Raster function - I was using ECW file which are not supported. Switched over to TIFFs and the code works - kinda - just need to figure the looping. Creates first file properly and then quits - this is due to my rasterList.next() which is a 9.3 function - need to figure the 10.

Cheers,

mike
0 Kudos
MikeBly
Occasional Contributor
Hi,

I managed to get the code to start working, let it run through the renaming of a few of the files - the new problem is the quality of the new raster file. There are two attachments for those who may be curious.

I found that the pixel value remains - however the stretched value is changed upon running the script. I have found a work around outside of python, but if there any ideas as to why the stretched value would get modified, be great to hear.

Thanks again,

MIke
0 Kudos