AnsweredAssumed Answered

Raster Calculator ArcMap Python

Question asked by workshop1 on Mar 17, 2020
Latest reply on Mar 18, 2020 by workshop1

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 import *
gp = arcgisscripting.create()
gp.OverWriteOutput = 1
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"
# Get a list of grids in the workspace.
rasters = gp.ListRasters("","TIF")
raster =
while raster:
    print raster
    raster =
raster =
print gp.GetMessages()
while raster:
    # Set local variables
    InRaster =  raster
    # Set the outputname for each output to be the same as the input.
    OutRaster = out_workspace + "/" + raster
    InExpression ="Con("+ InRaster +" <=  - 1,0,"+ InRaster +")", OutRaster)
    print raster
    #print InExpression
    raster =
    # If an error occurred while running a tool, then print the messages.
    print gp.GetMessages()

Any help would be highly appreciated.