Reclass with ArcPy

5810
9
Jump to solution
11-15-2015 10:27 AM
KONPETROV
Occasional Contributor III

Hi I am trying to bulid a python tool in which the user will import a DEM and that tool will reclassify it in 3 classes, for maxheight-10, maxheight-20 & maxheight-30 meters to use it for other process. I have created that code but I always get an error that RemapRange is not defined. Why is that? I am using ArcGIS 10.2.2

# Import system modules
import arcpy


# Set environment settings
inWorkspace = arcpy.GetParameterAsText(0)
inDEM = arcpy.GetParameterAsText(1)
outDEM = arcpy.GetParameterAsText(2)


# Get Raster Properties
maxvalue = arcpy.GetRasterProperties_management(inDEM, "MAXIMUM")
minvalue = arcpy.GetRasterProperties_management(inDEM, "MINIMUM")
minvalue2 = (minvalue.getOutput(0))
maxvalue2 = (maxvalue.getOutput(0))


# Conversion of max value to integer
intmaxvalue = int(float(maxvalue.getOutput(0)))


# Creation of classes per 10 meters until intmaxvalue-30 meters
class1 = intmaxvalue - 10
class2 = intmaxvalue - 20
class3 = intmaxvalue - 30


#Reclass DEM
reclassfield = "Value"
myRemapRange = RemapRange([[minvalue, class3, 4], [class3, class2, 3], [class2, class1, 2], [class1, maxvalue2, 1]])
outReclass = Reclassify(inDEM, reclassfield, myRemapRange)
outReclass.save(outDEM)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

RemapRange—Spatial Analyst module | ArcGIS for Desktop shows how to deal with nodata values, it will always be a separate class

View solution in original post

9 Replies
DanPatterson_Retired
MVP Emeritus

There are 3 numbers  in the range you appear to have 2 RemapRange—Help | ArcGIS for Desktop

0 Kudos
KONPETROV
Occasional Contributor III

I tried that also, and I have the same error

0 Kudos
DanPatterson_Retired
MVP Emeritus

print out the remaprange so people can see the output without having to do it themselves

0 Kudos
KONPETROV
Occasional Contributor III

Traceback (most recent call last):

  File "C:\Users\KOSTAS\Desktop\code.py", line 25, in <module>

    myRemapRange = RemapRange([[minvalue, class3, 4], [class3, class2, 3], [class2, class1, 2], [class1, maxvalue2, 1]])

NameError: name 'RemapRange' is not defined

Failed to execute (MAXIMUMViewshedAnalysis)

This is the message

0 Kudos
DanPatterson_Retired
MVP Emeritus

Oh and check the 2nd code example, you need to import sa

from arcpy.sa import *

KONPETROV
Occasional Contributor III

Of course.. Now it succeded but it doesn't appear anywhere. At the parameters of the tool I have put the inDEM as Raster Layer/ Input and outDEM as Raster Layer/ Output. I don't see the problem

0 Kudos
DanPatterson_Retired
MVP Emeritus

Well, I can't tell since I don't know what the output dem filename is and whether you have your environments set to add the results automatically to disk, or whether you are running the script with arcmap running, or whether you are using an external python ide or the one built into arcmap.  More details are needed and print statements would help those on this site narrow down the problems you are having.

0 Kudos
KONPETROV
Occasional Contributor III

Excellent. The only problem is that I have a value that is propably is NO DATA and it appears separate from the classes. How can i fix that.

0 Kudos
DanPatterson_Retired
MVP Emeritus

RemapRange—Spatial Analyst module | ArcGIS for Desktop shows how to deal with nodata values, it will always be a separate class