For context I have two main polygon features: Larger watersheds, and smaller impaired catchments. My goal is to have a field within the larger watershed feature named "Is Impaired" containing Y/N values. If the Larger watershed intersects with any of the impaired catchments, it will return Y, and N if not. When I run the code, I get all null values. Anything you recommend? Don't have a ton of coding experience, and would love advice...
// Variable containing impaired catchment feature
var ImpCatchments = FeatureSetByName($Datastore, "Catchments_Impaired")
//If larger watershed boundary feature intersects with any smaller impaired catchments features return "Y/N"
if (Intersects($feature,ImpCatchments) == True)
{
Return "Y";
}
else
{
Return "N";
}
Solved! Go to Solution.
When running Intersects between a Feature and a FeatureSet, the return is another FeatureSet, not a boolean value. You only get a boolean when you run it between two features. Using IIF still works just fine, but you'll need to write something that will evaluate to true or false. An easy way would be to check the Count of the returned set, as anything > 0 means an intersection was found.
IIf(Count(Intersects(ImpCatchments, $feature) > 0), "Y", "N");
The order doesn't matter, the function picks up which is the feature, which the set.
You're using the Intersects function for FeatureSet, where the parameters are in the order of features, then inputGeometry. You're providing them in reverse. Try this, which uses IIf to simply the returns:
// Variable containing impaired catchment feature
var ImpCatchments = FeatureSetByName($datastore, "Catchments_Impaired")
//If larger watershed boundary feature intersects with any smaller impaired catchments features return "Y/N"
IIf (Intersects(ImpCatchments, $feature), "Y", "N");
I am getting an error for line 5 of "bool type expected"
When running Intersects between a Feature and a FeatureSet, the return is another FeatureSet, not a boolean value. You only get a boolean when you run it between two features. Using IIF still works just fine, but you'll need to write something that will evaluate to true or false. An easy way would be to check the Count of the returned set, as anything > 0 means an intersection was found.
IIf(Count(Intersects(ImpCatchments, $feature) > 0), "Y", "N");
The order doesn't matter, the function picks up which is the feature, which the set.
Thanks for correcting my mistake about the output of this Intersects. And I'm surprised that order doesn't matter. It's great that it will sort out what is the feature and what is the set, but it's not something to count on for all functions!