0

I would like to build a script tool using Arcpy that reclassifies a raster layer based on a single user input parameter. For example, if the user inputs the number 7, then 0 - 7 would reclassify as 1, anything > 7 would become NoData.

The reason I need this is; I am building a site selection tool which contains many processes. In the middle of the tool there is a Reclassify process. The workflow goes something like this:

Elevation > Slope > Slope + 0.5 > Int > Reclassify > Raster to Polygon - This is the final vector that becomes part of other vector analysis to perform a site selection. It is a polygon of all areas of suitable slope.

I have been playing around with various attempts but to no avail, mostly because the Reclassify tool will not take a variable as part of the input. Everything else in the tool works fine but I don't know to have a user-defined input determine the Reclassify process.

# Import arcpy module
import arcpy
from arcpy.sa import *

# Script arguments
Elevation_Data = arcpy.GetParameterAsText(0)
Slope_Value = arcpy.GetParameterAsText(1)

# Local variables:
Slope_1 = "D:\egm722\Data\Scratch.gdb\\Slope_1"
Int_Slope = "D:\egm722\Data\Scratch.gdb\\Int_Slope"
Reclass = "D:\egm722\Data\Scratch.gdb\\Reclass"
RasPoly = "D:\egm722\Data\Scratch.gdb\\RasPoly"

# Process: Slope
arcpy.gp.Slope_sa(Elevation_Data, Slope_1, "DEGREE", "1", "PLANAR", "METER")

# Process: Raster Calculator
Slope_2 = Raster(Slope_1) + 0.5
Slope_2.save("D:\egm722\Data\Scratch.gdb\\Slope_2")

# Process: Int
arcpy.gp.Int_sa(Slope_2, Int_Slope)

# Process: Reclassify
arcpy.gp.Reclassify_sa(Int_Slope, "VALUE", "0 Slope_Value 1", Reclass, "NODATA")

# Process: Raster to Polygon
arcpy.RasterToPolygon_conversion(Reclass, RasPoly, "SIMPLIFY", "VALUE")

Here, I have attempted the variable Slope_Value to be the user-defined input as a script tool parameter type 'Long', but of course this does not work.

enter image description here

Traceback (most recent call last):
File "D:\egm722\elev.py", line 26, in <module>
arcpy.gp.Reclassify_sa(Int_Slope, "VALUE", "0 Slope_Value 1", Reclass, "NODATA")
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\geoprocessing\_base.py", line 510, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 000622: Failed to execute (Reclassify). Parameters are not valid.
ERROR 000628: Cannot set input into parameter remap.

I cannot skip the reclassify process and delete values from the 'Raster to Polygon' output (using Select tool for example) because converting non-reclassified Raster layers using 'Raster to Polygon' takes far too long for it to be considered a viable tool.

0

I solved the issue above by placing the remap within a list variable:

remap = RemapRange([[0,Slope_Value,1]])
Reclass = Reclassify(Int_Slope, "VALUE", remap, "NODATA")
Reclass.save(os.path.join(temp_Fgdb + "\\Reclass"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.