Hi,
I tried to make masked raster.
At first, making mask raster, and then SetNull for input raster.It's very common process.
All processes is well ,but NoData setting differs according to file format in raster save method....
I've checked following two format.
Unfortunately, I need to save in TIF format ,so it is just the problem.
I tried arcpy.env.nodata setting. However, Noting had changed.
What should I do?
# -*- coding: utf-8 -*-
# Import arcpy module
import arcpy
import sys
import osclass LisenceError(Exception):
pass# Check Spatial Analyst license
try:
if arcpy.CheckExtension("Spatial") == "Available":
arcpy.CheckOutExtension("Spatial")
else:
# raise a custom extension
raise LisenceError
except LisenceError:
print("Spatial Analyst License is unavailable")
arcpy.AddMessage("Spatial Analyst License is unavailable")
def makeCoheMask(coheRas, ccthresh):
try:
coheMask = arcpy.sa.Con(arcpy.Raster(coheRas) < ccthresh, 0, 1)
return coheMask
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
def makeSlopeMask(dem, geoid, angle, heightType, zfactor):
try:
arcpy.env.cellSize = "MINOF"TMP_SLOPE = arcpy.env.scratchWorkspace + '\\tmp_slope'
arcpy.Slope_3d(dem, TMP_SLOPE, 'DEGREE', zfactor)
return slopeMask
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
def makeLSMask(lsData, type):
try:outRas = arcpy.sa.Con(arcpy.Raster(lsData) > 1, 0, 1)
return outRas
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
# Set overwrite option
arcpy.env.overwriteOutput = True# Arguments
inputRas = sys.argv[1]
coheFlg = sys.argv[2]
coheRas = sys.argv[3]
ccthresh = sys.argv[4]
slopeFlg = sys.argv[5]
dem = sys.argv[6]
zfactor = sys.argv[7]
angle = sys.argv[8]
lsFlg = sys.argv[9]
lsData = sys.argv[10]
output = sys.argv[11]try:
input_Raster = arcpy.Raster(inputRas)
if coheFlg.lower() == 'true':
mask_cohe = makeCoheMask(coheRas, float(ccthresh))
else:
arcpy.AddMessage('NOT applied coherence mask')
mask_cohe = 1
if slopeFlg.lower() == 'true':
mask_slope = makeSlopeMask(dem, geoid, float(angle), heightType, float(zfactor))
else:
arcpy.AddMessage('NOT applied slope mask')
mask_slope = 1
if lsFlg.lower() == 'true':
mask_ls = makeLSMask(lsData, type)
arcpy.AddMessage('finish making LS mask')
else:
arcpy.AddMessage('NOT applied LS mask')
mask_ls = 1
conRas = arcpy.sa.Int(mask_cohe * (mask_slope * mask_ls))
outSetNull = arcpy.sa.SetNull(conRas, input_Raster, "VALUE = 0")
outSetNull.save(output)
if arcpy.Exists(TMP_SLOPE):
arcpy.Delete_management(TMP_SLOPE)except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
Solved! Go to Solution.
Nodata does vary based on the type of grid saved since
you can control it through the environment settings
http://desktop.arcgis.com/en/arcmap/latest/tools/environments/nodata.htm
then you can refer to prior to using SetNull
http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/set-null.htm
Nodata does vary based on the type of grid saved since
you can control it through the environment settings
http://desktop.arcgis.com/en/arcmap/latest/tools/environments/nodata.htm
then you can refer to prior to using SetNull
http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/set-null.htm
Thanks your reply
I set arcpy.env.nodata prior to using SetNull, trying all method, but I couldn't solve the problem...
(I think arcpy.env.nodata = "NONE" is valid in this case, is my understanding correct?)
I guess arcpy.env.nodata could not work in my script, but why?
you indicate that nodata values are displayed... that should now a symbology issue
which doesn't have a solution within arcpy except for using a lyr file.
Can you confirm that the nodata values are truly nodata or are they now being treated as values?
Sorry for my poor explanation
I'm afraid it's not a symbology issue, but, nodata values(i.e -3.40282e+038) are treated as valid value.
-3.40282e+038 is treated as valid value...
Of course, I set nodata symbol transparent.
nodata setting in this test data are below
input : 0(32bit float)
mask:nothing(1bit value 0or1)
0 has two meaning.Therefore I assigned -9998 to nodata of input raster.
But,it didn't work...
this is what the no data value should have been set to, the largest negative number
-3.40282e+038
Thanks Dan!
during process, no data value is set to.(assigned many values)
So, I use arcpy.SetRasterProperties_management() for every output in script.
Everything goes well!
glad it worked out! you should close this thread out so that people know a solution was found