1

I'm trying to create a python script tool that will take in a DEM/raster as a parameter, pull out the maximum and minimum elevation values, and iterate through this range of values at a specified counting interval.

This script outputs the resulting raster masks to an output geodatabase, as another parameter. I keep getting the error '000865: Input Raster: inDEM does not exist' when I try to run my script tool. I'd like help resolving this issue in my code, as I'm not sure what the cause is.

import arcpy
from arcpy.sa import *
import os

arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True


inDEM = arcpy.GetParameterAsText(0)
intervalElevation = int(arcpy.GetParameterAsText(1))
outGDB = arcpy.GetParameterAsText(2)

elevMinResult = arcpy.GetRasterProperties_management("inDEM", "MINIMUM")
elevMaxResult = arcpy.GetRasterProperties_management("inDEM", "MAXIMUM")

minElevation = elevMinResult.getOutput(0)
maxElevation = elevMaxResult.getOutput(0)

myElevations = range(minElevation, maxElevation, intervalElevation)

for elev in myElevations:

    outDEM = os.path.join(outGDB, "lessthan" + str(elev))
    outLessThan = LessThan(inDEM, elev)
    outLessThan.save(outDEM)
    print "Finished " + outDEM
2

You are getting the name of the input raster with this line and assigning it to a variable inDEM:

inDEM = arcpy.GetParameterAsText(0)

But in this line you are proving a string.

elevMinResult = arcpy.GetRasterProperties_management("inDEM", "MINIMUM")

As you have the name of the raster in the variable all you need to do is remove the double quotes around "inDEM" and you are referencing the variable which is holding the true raster layer name.

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.