I wrote a Python script which is supposed to produce a slope map with 6 classes each one being from 0-3.99, 4-9.99, 10-15.99, 16-30.99, 31-60.99, 61+ (Although for testing purposes the max is 789.54). The slope map produced from the code should look exactly like Slope_tif6 and Slope_tif7 (which both have 6 classes and have those exact values for each class), however, the values are completely different and has 9 classes instead of 6.
import arcpy
from arcpy import env
from arcpy.sa import *
#set the workspace environment
env.workspace = "C:\Users\user\OneDrive\Documents\ArcGIS\ArcMap_Folder"
class Raster:
def __init__(self, inRast):
self.inRast = inRast
value = "Value"
#create a variable which will store the remap (this will be the same for all rasters)
remap = RemapRange([[0, 3.99, 1], [4, 9.99, 2], [10, 15.99, 3], [16, 30.99, 4], [31, 60.99, 5], [61, 789.548, 6]])
#Create an object of the Raster class
rast_obj1 = Raster("Slope_tif7.tif")
#Create array to store rasters
rast_arr = []
#Append the object(s) to the empty array
rast_arr.append(rast_obj1)
#Create function to
def changeRange(obj):
#Call the Reclassify function and store it in a variable
reclassed = Reclassify(obj.inRast, obj.value, obj.remap)
#Save the output
reclassed.save("C:\Users\user\OneDrive\Documents\ArcGIS\ArcMap_Folder.tif")
arcpy.CheckOutExtension("spatial")
#Loop through the array to change all of their values
for obj in rast_arr:
changeRange(obj)
arcpy.CheckInExtension("spatial")
What am I doing wrong?