Attribute Rules - Constraint rule for creating point outside a polygon layer

630
1
Jump to solution
03-21-2022 05:28 PM
cwlee27
New Contributor II

Hello,

I'm trying to create a simple attribute rule to prevent a user from creating a point outside a polygon layer.  My code is below, when I hit validate it seems to check out but when I try creating points it returns the error even if the point is inside the polygon layer I'm referencing.  Any feedback is much appreciated, thanks!

-------------------------------------------------------------------------------------------

// variable for 'AOR' layer
var aor = FeatureSetByName($datastore, "aor", ['*'], True);

// boolean "if statement" for determining if point intersects the 'aor' layer
if (Within($feature, aor) == True)
return True
else
return False

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

From the documentation:

This function has 2 signatures:

You use the second version (with a geometry for the inner feature and a feature set for the outer features) and expect a boolean return value, but it actually returns a feature set of polygons. So you have to check if this feature set contains any features.

var aor = FeatureSetByName($datastore, "aor")
return Count(Within($feature, aor)) > 0
// you could also do this
//return First(Within($feature, aor)) != null

 


Have a great day!
Johannes

View solution in original post

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

From the documentation:

This function has 2 signatures:

You use the second version (with a geometry for the inner feature and a feature set for the outer features) and expect a boolean return value, but it actually returns a feature set of polygons. So you have to check if this feature set contains any features.

var aor = FeatureSetByName($datastore, "aor")
return Count(Within($feature, aor)) > 0
// you could also do this
//return First(Within($feature, aor)) != null

 


Have a great day!
Johannes
0 Kudos