Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why is my ArcPy script in ArcGIS 10.1 failing to set null cell values below three standard deviations beyond the mean?

import arcpy, sys, os

#Accept input and output raster
inRas = sys.argv[1]
outRas = sys.argv[2]

#Pull mean and standard deviation from input raster
meanie = arcpy.GetRasterProperties_management(inRas, "MEAN")
meanres = meanie.getOutput(0)
meanfloat = float(meanres)

stdev = arcpy.GetRasterProperties_management(inRas, "STD")
stdres = stdev.getOutput(0)
stdfloat = float(stdres)

#Calculate threshold value
threshold = meanfloat + (3 * stdfloat)
threstring = str(threshold)

#Create where clause
whereClause = "VALUE < " + threstring

#Test output
arcpy.AddMessage (whereClause)

#Run SetNull
outRas = arcpy.SetNull(inRas, inRas, whereClause)

This results in the following error:

Traceback (most recent call last):
File       "Z:<directory-redacted>\Nullify.py", line 27, in <module>
outRas = arcpy.SetNull(inRas, inRas, whereClause)
AttributeError: 'module' object has no attribute 'SetNull'

Failed to execute (Nullifiy).
share|improve this question
up vote 5 down vote accepted

arcpy.SetNull does not exist. You are wanting arpy.sa.SetNull.

Here's the SetNull page for 10.1. If you notice in some of the examples there is:

from arcpy.sa import *

and you see that SetNull is used, but the import * from arcpy.sa drops the arcpy.sa from arcpy.sa.SetNull. And be sure to check out the spatial analyst license

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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