I am having trouble for writing script in Python (ArcGIS 10.1). The task is generally divide each raster by 100. I have many of these raster files…
So what I've done is the following:
from arcpy.sa import *
arcpy.workspace="C:/Users/Vaio/.../Monthly_Original.gdb"
rasterlist=arcpy.ListRasters(p)
for k in range():
OutRaster=(Raster(rasterlist[k])/100
OutRaster.Name='p_2000_*.*'
OutTaster.Save(OutRaster.Name)
I have an Error in line 6. I am very new to any sort of programming.
Best Answer
Insert 'import arcpy' at the top of your code (NameError: name 'arcpy' is not defined)
No indentation needed after the import statements
Check out the ArcGIS Spatial Analyst extension license using 'arcpy.CheckOutExtension("Spatial")' (RuntimeError: ERROR 000824: The tool is not licensed.)
Assuming that 'arcpy.workspace="C:/Users/Vaio/.../Monthly_Original.gdb"' is not the actual directory path run in the code, but merely abbreviated for posting here - you still need to state arcpy
.env
.workspace'ListRasters(p)' needs to have the variable 'p' previously defined (NameError: name 'p' is not defined)
'range()' expects atleast one argument - or try something like for '
k in rasterlist:
' (TypeError: range expected at least 1 arguments, got 0)This is the reason for the invalid syntax error: 'OutRaster=(Raster(rasterlist[k])/100' has two opening parentheses but only one closing parenthesis
Do not use '.Name' for assigning the output name (AttributeError: 'Raster' object has no attribute 'Name') Note: (lower case) '.name' is Read Only
What are the '*' in 'p_2000_*.*' supposed to mean? If you want variables then you may need a counter variable defined, or extract the original file name from the item used in the for loop with rasterlist to replace the first '*' (perhaps the second '*' could be replaced with the text for the desired output raster file extension). The '*' characters used in the output name will cause more errors. (RuntimeError: ERROR 010093: Output raster format UNKNOWN is unsupported.)
The very last line needs to be changed from 'OutTaster' to 'OutRaster' (NameError: name 'OutTaster' is not defined)
The '.save' cannot be capitalized (AttributeError: 'Raster' object has no attribute 'Save')
EDIT: Now that I finally have access to the software I was able to revise your code - you may need to modify to suit your actual data (see comments and online help):