NoData setting differs according to file format in raster save method

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

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.

  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):
  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))

0 Kudos
1 Solution
7 Replies
YasunariMorita
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
DanPatterson_Retired
MVP Emeritus

you indicate that nodata values are displayed... that should now a symbology issue

http://desktop.arcgis.com/en/arcmap/latest/manage-data/raster-and-images/symbolizing-values-of-nodat...

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?

YasunariMorita
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
DanPatterson_Retired
MVP Emeritus

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

-3.40282e+038

YasunariMorita
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
DanPatterson_Retired
MVP Emeritus

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

0 Kudos