2

I'm creating a model that queries the number of features in a feature class and runs one of two scripts depending on if the feature class is empty or not.

I'm using Get Count to calculate the number of features with the output being 'Feature Count'

I then have two calculate values 'Policy Detected' and 'No Policy Detected' both set to Boolean data types

Policy detected is:

FeatureCount(%Feature Count%)
def FeatureCount(n):
if n> 0:
    return True
else:
    return False

No Policy Detected is:

FeatureCount(%Feature Count%)
def FeatureCount(n):
if n >0:
    return False
else:
    return True

When there are features in the feature class (n>0), 'Policy detected' has a 'True' output and 'No Policy detected has a 'False' output - all correct!

When there are no features in the featureclass (n=0) then both 'Policy detected' and 'No Policy detected' show a False output instead of 'False and 'True'

Any ideas what's wrong?

.enter image description here

0

You logic is flawed as well as the use of the Get Count tool.

Firstly if Get Count is returning a zero then in the world of model builder this is interpreted as FALSE. You have made this output the precondition to your Policy tools. So as your precondition is FALSE (because count is zero) then neither of the tools will run.

If you are attempting an if/then/else logic you need to be reading the help file and understanding how it is done in modelbuilder. There is lots of advice and examples to study.

  • So the precondition between the Get Count output and the Policy detected calculation is what's causing the problem? The 'Feature Count' output is an integer but the precondition assumes 0 = False? – user6459384 Mar 26 at 6:37
  • I've tried the tool using 'n>1' as the condition and running it with Get count outputting 1 and >1 and the if/else works perfectly. As you said, the precondition assumes 0 is false and everything else is true. Thanks – user6459384 Mar 26 at 6:43

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.