Select to view content in your preferred language

Arcade coding for intersection of two polygons

1277
4
Jump to solution
10-04-2023 10:07 AM
BrennonPeterson
Emerging Contributor

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...

Large watersheds and small catchments.png

// 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";
}

1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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.

jcarlson_0-1696443185218.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

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");

 

BrennonPeterson
Emerging Contributor

I am getting an error for line 5 of "bool type expected"

0 Kudos
jcarlson
MVP Esteemed Contributor

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.

jcarlson_0-1696443185218.png

 

- Josh Carlson
Kendall County GIS
KenBuja
MVP Esteemed Contributor

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!

0 Kudos