Set Null value for raster datasets

1572
2
03-08-2013 01:45 AM
TrinaChakravarty
New Contributor
Hi,

I am writing a Python code to automate a process. In it I need to use SetNull function several times to extracting the required values from the raster dataset.
I am using the following line of code, and the tool is running without any error; but it is not providing the desired output.

arcpy.gp.RasterCalculator_sa("SetNull(ZMAXRas == -99,ZMAXRas)",outWorkspace + inputASCII [:-4] + "_W")

Where, ZMAXRas is the input raster variable; outWorkspace and inputASCII are the others variables, those I have used for to retain the naming convention of my output data.

Can anyone please suggest why I am not getting the raster without '-99' value after running the script.

For your information, I am using ArcGIS 10.1.

Thanks in advance.
Trina.
Tags (2)
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
I need to use SetNull function several times to extracting the required values from the raster dataset.

I am using the following line of code, and the tool is running without any error; but it is not providing the desired output.

arcpy.gp.RasterCalculator_sa("SetNull(ZMAXRas == -99,ZMAXRas)",outWorkspace + inputASCII [:-4] + "_W") 


I recommend using the 10.x Python map algebra instead. This enables more efficiency in processing and also is easier to read/debug. (Raster Calculator is really more for interactive use or ModelBuilder.)

Try this and see if it works better:

from arcpy.sa import *
arcpy.env.workspace = outWorkspace
ZMAXRas = Raster(ZMAXRas) # convert a path to a raster object
outRas = SetNull(ZMAXRas == -99,ZMAXRas)
outRas.save(inputASCII[:-4] + "_W")
0 Kudos
TrinaChakravarty
New Contributor
Thanks for your reply. It is working now. I tried both ways; the main problem was with the conversion of the path to raster. Anyway thank you very much again for your suggestion.

Thanks
Trina
0 Kudos