Automate setting null values of rasters to zero

Last Published: April 25, 2020


Instructions provided describe how to assign the NoData cells of rasters to zero values.

Various spatial analysis applications require raster NoData cells to be factored into an analytical operation. Since NoData cells are ignored in any analysis, such requirements can only be met if those cells have a specific value assigned to them.

The following script demonstrates how to assign NoData cells of rasters in a workspace to zero values using map algebra.

This procedure assumes that the input raster data is in Esri Grid format. See the Related Information section below.


#import modules
import arcpy, sys, os
from arcpy import env
from import *

env.workspace = arcpy.GetParameterAsText(0)

#Create raster directory
ras_dir = "{0}/ras_dir".format(env.workspace)

if not os.path.exists(ras_dir):

rasterList = arcpy.ListRasters("*") #, "GRID")

#Set raster null values to 0
for raster in rasterList:

	arcpy.AddMessage("Reading {0}".format(raster))
	outras = Con(IsNull(raster),0,raster)
	arcpy.AddMessage("Setting null for {0}".format(raster))"{0}/{1}".format(ras_dir, raster))
	arcpy.AddMessage("Saving {0}".format(raster))

Article ID:000014695

  • ArcMap

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic