Hi ,
I have 70 raster files and I want to make 3 new raster from each of the 70 raster. For that, I want to automate the process using python script and store the output new raster based on the raster file name plus value field. For example, My input raster is 01367620-r-r and 3 value fields are 9,11, and 13. So the output folder should be 01367620-r-r-9. 01367620-r-r-11, and 01367620-r-r-13. When I ran my code, I got the below error message. I think, I am doing mistake at "outname=os.path.join(outws,str(i), str(j))" in my code. I would appreciate your suggestion/input.
Error Message:
Traceback (most recent call last):
File "C:/Subhasis/Test/Neshanic_Python/Neshanic-test.py", line 23, in <module>
attExtract.save(outname)
RuntimeError: ERROR 000875: Output raster: C:\Subhasis\Test\Neshanic_Python\extract\01367620-r-r\9's workspace is an invalid output workspace.
I am providing my code below.
import arcpy, os
from arcpy import env
from arcpy.sa import *
#To overwrite output
arcpy.env.overwriteOutput = True
#Set environment settings
env.workspace = "C:/Subhasis/Test/Neshanic_Python"
outws="C:/Subhasis/Test/Neshanic_Python/extract"
#checkout ArcGIS spatial analyst extension license
arcpy.CheckOutExtension("Spatial")
# set local variable
inraster = ["01367620-r-r"]
for i in inraster:
STI_list=[9,11,13]
for j in STI_list:
attExtract = ExtractByAttributes(str(i), "VALUE>=" + str(j))
outname=os.path.join(outws,str(i), str(j))
attExtract.save(outname)
Thanks!
If this question is related to the rasters created in your thread Re: loop for value and counts in raster attribute, then Dan Patterson is absolutely right. The problem occurs in the line:
This should be:
The first creates an outname of: C:/Subhasis/Test/Neshanic_Python/extract\01367620-r-r\9
The second creates an outname of: C:/Subhasis/Test/Neshanic_Python/extract\01367620-r-r9
The os,path.join will place a slash between each parameter. This causes the value "j" to be the raster name and the value "i" is interpreted as folder.
BTW: if the thread Re: loop for value and counts in raster attribute is solved, you should mark it as answered!
Kind regards, Xander