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
    #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
    #Loop through the array to change all of their values 
    for obj in rast_arr:

What am I doing wrong?

enter image description here

  • 1
    I'm going to guess that the upper bound is not the same as the lower bound for the next class? What happens if you value is 3.9905? It falls outside class 1 and not within class 2... Also the indentation of your code is wrong and that's very important when showing such code questions as we don't know if that is what you did or it was a silly paste error?
    – Hornbydd
    Jun 21 at 23:41


Your Answer

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

Browse other questions tagged or ask your own question.