Hi All,
I am trying to do some calculation on Raster using raster calculator in python. I have several restaer and I implemented the calculation using loop. I was working well when I was using ArcMap 9, and now I am using version 10.7. but it gives some errors. The code is below:
import sys, string, os, arcgisscripting, math, arcpy
from arcpy import env
from arcpy.sa import *
gp = arcgisscripting.create()
gp.OverWriteOutput = 1
gp.CheckOutExtension("spatial")
arcpy.CheckOutExtension("spatial")
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/Desktop10.7/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
gp.workspace = "E:/JASTTpaperWork/Data/Processed/TIFF/"
out_workspace = "E:/JASTTpaperWork/Data/Processed/TIFF/ArcGIS02"
InMask = "E:/JASTTpaperWork/Data/Shapefile/KRG.shp"
rasters = gp.ListRasters("","TIF")
raster = rasters.next()
while raster:
print raster
raster = rasters.next()
rasters.reset()
raster = rasters.next()
print gp.GetMessages()
while raster:
InRaster = raster
OutRaster = out_workspace + "/" + raster
InExpression ="Con("+ InRaster +" <= - 1,0,"+ InRaster +")"
arcpy.gp.RasterCalculator_sa(InExpression, OutRaster)
gp.CheckOutExtension("Spatial")
print raster
raster = rasters.next()
print gp.GetMessages()
Any help would be highly appreciated.