First of all thank you for anybody willing to help me.
I am trying to learn how to create a tool that will calculate the multiplication of 4 rasters. The code in python works and gives me an output raster but the tool I am trying to create does not. I am not sure if I am calling the rasters right with GetParameters. Please help I appreciate any comments on the code. Thank you
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
def getParameterInfo(self):
"""Define parameter definitions"""
# First parameter
param0 = arcpy.Parameter(
displayName="1",
name="f1raster",
datatype="DERasterDataset",
parameterType="Required",
direction="Input")
# Second parameter
param1 = arcpy.Parameter(
displayName="2",
name="f2raster",
datatype="DERasterDataset",
parameterType="Required",
direction="Input")
# Third parameter
param2 = arcpy.Parameter(
displayName="3",
name="f3raster",
datatype="DERasterDataset",
parameterType="Required",
direction="Input")
# Fouth parameter
param3 = arcpy.Parameter(
displayName="4",
name="f4raster",
datatype="DERasterDataset",
parameterType="Required",
direction="Input")
params = [param0, param1, param2, param3]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
f1raster = arcpy.GetParameter(0)
f2raster = arcpy.GetParameter(1)
f3raster = arcpy.GetParameter(2)
f4raster = arcpy.GetParameter(3)
outraster = (f1raster * f2raster * f3raster * f4raster)
outraster.save("C:/REP/REP.tif")
return