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.
- ESRI Gird:output raster has no problem, NoData pixels are not displayed in ArcMap.
- TIF: Not working NoData value. NoData pixels have values(-3.4028235e+038 or 0). So, NoData pixels are displayed in ArcMap.
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 os
class 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))