This modelbuilder works well until the raster to polygon step. At that step, rasters without features cause an error(error 010151). I would like to put in a step before raster to polygon that causes the model to skip over these "feature-less" rasters. I have very little experience with python and rasters and need some help. I tried to make a row count sequence but it didn't work because the rasters did not have a table to check.
I shall caveat my answer with the warning that I have little modelbuilder experience, but here's what I've been able to figure out.
I found this post, and for me the third method worked best for determining if a raster has values in it.
I created a
.py file and added this code:
import arcpy import numpy ras = arcpy.GetParameterAsText (0) array = arcpy.RasterToNumPyArray(ras) if numpy.max(array) > 0: arcpy.SetParameterAsText (1, ras) else: arcpy.SetParameterAsText (1, "") arcpy.SetParameterAsText (2, "True")
I then created a custom ArcGIS toolbox and added my script:
I added some basic properties:
I added the path to the python file:
I set the parameter properties as below. Make sure
Has Values and
Has No Values have their direction set to
I was then able to incorporate the script into model builder by drag/dropping it:
If the raster has values, the Has Values output will be a string of the path to the raster. If not, it will be an empty string.