Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

As mentioned in the title, simple script 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).

If anyone has any ideas, I'd really appreciate the help, thanks so much.

-Alex

share|improve this question
add comment

1 Answer

up vote 4 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
    
Done, thanks so much! –  AlexB May 1 '13 at 16:45
add comment

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.