Select to view content in your preferred language

Arcade within() function; points within polygon

1207
7
Jump to solution
04-24-2024 06:05 AM
TylerT
by
Frequent Contributor

Hello,

I have two feature classes, one point feature class, and one polygon feature class.  When a point falls within a polygon I would like to symbolize differently than a point that is not within a polygon.  Does anyone have an example arcade expression to accomplish this?  Thank you.

Tyler

ArcGIS Pro 3.2.0

0 Kudos
1 Solution

Accepted Solutions
AlfredBaldenweck
MVP Regular Contributor

So... This is an expression that is actually pretty simple in theory.

This expression works fine for popups.

var wit = FeatureSetByName($datastore, "poly")
var check = (Within($feature, wit))
if (check == true){
    return "Inside"
}
else {
    return "Outside"
}

 

The problem that makes this currently impossible is that $featureset is not available for Symbology or Labeling.

When will Arcade get more useful, esp with Feature... - Esri Community

Basically, because it's designed to execute on a feature-by-feature basis, a call is made to wherever the data lives for every. single. feature. instead of just loading the featureset into memory or caching it in the map.

To avoid it being super slow, we instead only get to reference featuresets for popups, since you can only Identify a few features at a time. (And this is still really slow: See @jcarlson's blog post for tips to improve $featureset stuff Improving Expression Performance: A Custom Functio... - Esri Community)

 

Long story short: Should be very easy, is currently impossible due to technical limitations.

As an alternative, if your data lives in an enterprise geodatabase, you could use a query layer or a view to return a computed column detailing if the points are "within" and then symbolize off of that.

 

View solution in original post

7 Replies
AlfredBaldenweck
MVP Regular Contributor

So... This is an expression that is actually pretty simple in theory.

This expression works fine for popups.

var wit = FeatureSetByName($datastore, "poly")
var check = (Within($feature, wit))
if (check == true){
    return "Inside"
}
else {
    return "Outside"
}

 

The problem that makes this currently impossible is that $featureset is not available for Symbology or Labeling.

When will Arcade get more useful, esp with Feature... - Esri Community

Basically, because it's designed to execute on a feature-by-feature basis, a call is made to wherever the data lives for every. single. feature. instead of just loading the featureset into memory or caching it in the map.

To avoid it being super slow, we instead only get to reference featuresets for popups, since you can only Identify a few features at a time. (And this is still really slow: See @jcarlson's blog post for tips to improve $featureset stuff Improving Expression Performance: A Custom Functio... - Esri Community)

 

Long story short: Should be very easy, is currently impossible due to technical limitations.

As an alternative, if your data lives in an enterprise geodatabase, you could use a query layer or a view to return a computed column detailing if the points are "within" and then symbolize off of that.

 

TylerT
by
Frequent Contributor

@AlfredBaldenweck 
Interesting.  I guess that might explain why I was getting errors with my Arcade attempts.  Thank you.

Tyler

0 Kudos
Kohl_Haessly
Emerging Contributor

Hey @AlfredBaldenweck 

I took your expression and updated for my map. I am trying to determine if an address point is within the city boundary or outside. The expression works, but I am only getting outside even if the address is within the polygon (city boundary). I am using this expression below on my address point layer. Do you have any pointers for this expression? 

 

var city = FeatureSetByName($map, "City_Boundary")
var check = (Within ($feature, city))
if (check == true) {

  return "Inside"
}
else {
  return "Outside"
}
0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Not sure which environment you're using, but a common pitfall of Arcade's geometry functions is that they evaluate at your current scale, which means things will return different values depending on where you're zoomed.

Geometry functions | ArcGIS Arcade | Esri Developer

Feature geometries in the visualization and labeling profiles are generalized according to the view's scale resolution to improve drawing performance. Therefore, using a feature's geometry (i.e.$feature) as input to any geometry function in these contexts will return different results at each scale level. Other profiles, such as popup, provide the full resolution geometry.

I think that's probably what's going on. You might have better luck calculating a field with that expression and using that for your popup or whatever? I'm not sure which scale is used to evaluate field calculations, but you should experiment and let me know.

0 Kudos
Kohl_Haessly
Emerging Contributor

Thank you for the response. I am using ArcGIS Online and I am trying to use this just in a Pop up. No matter where I am zoomed it only displays Outside.  I will review the Geometry Functions page. Thank you. 

0 Kudos
Kohl_Haessly
Emerging Contributor

Update I got it to work. Thank you!

0 Kudos
KGalluccio
Occasional Contributor

Hi, could you post what you did to your expression to get it to work?  I am having the same issue.

I click a polygon in my map and in the popup run this expression:

 var check = (Within(FeatureSetByName($map, 'General Election Polling Sites',['*'], true), $feature))

return check
 
This returns an empty featureset.  
0 Kudos