# Get Parameters infc = arcpy.GetParameterAsText(0) recl_rule = arcpy.GetParameterAsText(1) outfc = arcpy.GetParameterAsText(2) # Local Parameters recl_value = "VALUE" recl_data = "DATA" # Reclassify outRecl = arcpy.sa.Reclassify(infc, recl_value, recl_rule, outfc, recl_data) outRecl.save("outfc")
Thanks so much to everyone who posted on this, you've all helped me a lot!
It's still a bit buggy (remap values don't populate automatically), but I managed to get something working (10.7.1).
In order to activate the "Classify" button, which is initially grayed out, click on one of the other buttons... "Reverse New Values" or "Precision..." and that should activate the "Classify..." button. You can then choose the classification method you want and the no. of classes.
import arcpy, string
import numpy
from arcpy import env
from arcpy.sa import *
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 = [Remap]
class Remap(object):
def __init__(self):
self.label = "Remap"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
inputraster = arcpy.Parameter(
displayName="Input Raster ",
name="input1",
datatype="Raster Layer",
parameterType="Required",
direction="Input")
field = arcpy.Parameter(
displayName="Input Field ",
name="input2",
datatype="Field",
parameterType="Required",
direction="Input")
field.value = "Value"
field.enabled = True
remap = arcpy.Parameter(
displayName="ReMap ",
name="remap",
datatype="GPSARemap",
parameterType="Required",
direction="Input")
remap.parameterDependencies = [inputraster.name,field.name]
outputraster = arcpy.Parameter(
displayName="Output Raster ",
name="ouput1",
datatype="Raster Layer",
parameterType="Required",
direction="Output")
params = [inputraster,field,remap,outputraster]
return params
#####################################################################
### Insert this section to enable the remap buttons ###
def initializeParameters(self):
"""Refine the properties of a tool's parameters called when the tool is opened."""
self.params[2].parameterDependencies = [0]
return
######################################################################
def isLicensed(self):
return True
def updateParameters(self, parameters):
# if parameters[0].value:
# parameters[2].parameterDependencies = [parameters[0].name,parameters[1].name]
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
inRaster = parameters[0].valueAsText
field = parameters[1].valueAsText
outRaster = parameters[3].valueAsText
remap2 = parameters[2].valueAsText
messages.addWarningMessage(str(remap2))
outputraster = Reclassify(inRaster, field, remap2, "NODATA")
outputraster.save(outRaster)
return