# Skip empty rasters in ArcGIS

I'm trying to write some code to skip over empty raster sets when converting rasters to point (the empty sets stop the conversion, leaving me with a half complete model run).

I know that I can identify empty rasters using the ALLNODATA result from "Get Raster Properties" Create conditional to check if raster has value.

I know I can delete rasters using the Delete.management tool.

I know I should be able to create a branch using calculate value.

But I'm inexperienced with python and modelbuilder, and haven't been able to put this all together. Could someone help me figure out what I am doing wrong? My code and an image of the modelbuilder setup are below.

def fn(Property):

#Import modules
import arcpy

#ifelse statement
if Property == "1":
return "true"
elif Property == "0":
return "false"


• Try taking the second argument (Layer) out of Delete_management. What error are you getting and where does it happen in the process? – J Kelly Aug 26 '16 at 18:10
• Please define "empty set". What if a raster contains only a single value (e.g. 1)? Would this qualify as an empty raster? – Aaron Aug 26 '16 at 18:25
• Cross-posted as stackoverflow.com/q/39127665/820534 – PolyGeo Sep 20 '16 at 14:26

Here is one approach that utilizes numpy.unique() to find all the unique raster values. Essentially, if there is greater than 1 value in the raster, do something, else pass. You can easily alter the logic to look for specific values, or no values, if you prefer.

import arcpy, os
import numpy as np

raster = r'C:\path\to\singleband\raster.tif'

array = arcpy.RasterToNumPyArray(raster)

values = np.unique(array)

# Check to make sure there are more than 1 value in raster
if values > 1:
print "There are two or more values"
# Do something...