1

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"

ModelBuilderEx

  • 1
    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
  • 2
    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
1

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...
|improve this answer|||||

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.