NoData setting differs according to file format in raster save method

Jump to solution
07-06-2017 12:53 AM
New Contributor II


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.

  1. ESRI Gird:output raster has no problem, NoData pixels are not displayed in ArcMap.
  2. 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):

# Check Spatial Analyst license
  if arcpy.CheckExtension("Spatial") == "Available":
    # 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):
    coheMask = < ccthresh, 0, 1)
    return coheMask
  except arcpy.ExecuteError:

def makeSlopeMask(dem, geoid, angle, heightType, zfactor):
    arcpy.env.cellSize = "MINOF"

    TMP_SLOPE = arcpy.env.scratchWorkspace + '\\tmp_slope'
    arcpy.Slope_3d(dem, TMP_SLOPE, 'DEGREE', zfactor)
    return slopeMask
  except arcpy.ExecuteError:

def makeLSMask(lsData, type):

      outRas = > 1, 0, 1)
      return outRas
  except arcpy.ExecuteError:

# 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]


  input_Raster = arcpy.Raster(inputRas)

  if coheFlg.lower() == 'true':
    mask_cohe = makeCoheMask(coheRas, float(ccthresh))
    arcpy.AddMessage('NOT applied coherence mask')
    mask_cohe = 1

  if slopeFlg.lower() == 'true':
    mask_slope = makeSlopeMask(dem, geoid, float(angle), heightType, float(zfactor))
    arcpy.AddMessage('NOT applied slope mask')
    mask_slope = 1

  if lsFlg.lower() == 'true':
    mask_ls = makeLSMask(lsData, type)
    arcpy.AddMessage('finish making LS mask')
    arcpy.AddMessage('NOT applied LS mask')
    mask_ls = 1

  conRas = * (mask_slope * mask_ls))
  outSetNull =, input_Raster, "VALUE = 0")

  if arcpy.Exists(TMP_SLOPE):

except arcpy.ExecuteError:

0 Kudos
1 Solution

Accepted Solutions
7 Replies
MVP Legendary Contributor
New Contributor II

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?


0 Kudos
MVP Legendary Contributor

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?

New Contributor II

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...

0 Kudos
MVP Legendary Contributor

this is what the no data value should have been set to, the largest negative number


New Contributor II

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!

0 Kudos
MVP Legendary Contributor

glad it worked out!  you should close this thread out so that people know a solution was found

0 Kudos