Similar to Reclassify raster values of 9999 to NoData, leaving all other values alone, in ArcGIS Desktop?, I am attempting to convert numerical NoData values to actual NoData cells. The solution in the linked question doesn't work for me, however, as when I use the save method to save to TIFF the numerical values are reintroduced.

When I do this manually (using the GUI tools) I do not have the issue. When I use arcpy.gp.SetNull_sa (over arcpy.sa) I do not have the issue, but using the gp approach doesn't work on one of our team member's machines for some reason. I have not found much documentation on the gp appr, either.

I can save the outputs as GRID and export using the context menu because that tool allows you to supply a NoData value, but the Raster To Other Format (Conversion) tool doesn't give that option. It appears to work, regardless, but does not let you name the output (only the workspace), which means there's another step to add to the script (renaming). This solution seems too convoluted to be the right one, and also takes twice as long as the other methods.

So, what are methods for saving the output from an arcpy.sa tool in TIFF format with NoData intact?


arcpy.env.compression = "NONE"
arcpy.env.rasterStatistics = "STATISTICS 1 1"
arcpy.env.resamplingMethod = "NEAREST"
arcpy.env.snapRaster = inDEM
arcpy.env.tileSize = "128 128"
arcpy.env.pyramid = "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP"
arcpy.env.extent = inDEM
arcpy.env.nodata = "NONE"

This does not work:

con_ras = arcpy.sa.Con(arcpy.sa.IsNull(outBreachrast),outBreachrast,inDEM,""""Value" = 0""")

null_ras = arcpy.sa.SetNull(arcpy.sa.IsNull(inDEM),tempDEM,""""Value" = 1""")

This does (but not on everyone's computers):

arcpy.gp.IsNull_sa(inDEM, isnullDEM)
arcpy.gp.SetNull_sa(isnullDEM, tempDEM, outDEM, """"Value" =1""")

This also does, but does not let you specify file names:

con_ras = arcpy.sa.Con(arcpy.sa.IsNull(outBreachrast),outBreachrast,inDEM,""""Value" = 0""")

null_ras = arcpy.sa.SetNull(arcpy.sa.IsNull(inDEM),arcpy.sa.Con(arcpy.sa.IsNull(outBreachrast),outBreachrast,inDEM,""""Value" = 0"""),""""Value" = 1""")

tiff_ras= arcpy.RasterToOtherFormat_conversion(null_ras, outDir, "TIFF")

This behaviour may only happen in ArcMap, and may not be an issue in ArcCatalog, which is puzzling.

  • 1
    Looks a bit crowded here. I'd say using this 'from arcpy.sa import *' will help to make it more readable because you can do things like 'Gter=Con(outFocal>=DEM,outFocal-DEM)' without very long prefix. I.e. using field calculator expressions instead of actual tools – FelixIP Dec 8 '15 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.