1

This modelbuilder enter image description hereworks 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.

1

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:

Add Script

I added some basic properties:

Python tool properties 1

I added the path to the python file:

Add python file path

I set the parameter properties as below. Make sure Has Values and Has No Values have their direction set to Output:

Set parameter properties

I was then able to incorporate the script into model builder by drag/dropping it:

enter image description here

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.