Select to view content in your preferred language

Arcade Expression - Intersect and Find Features with Defined Value

1276
3
Jump to solution
04-13-2023 10:31 AM
Labels (2)
LukeCulleny
Emerging Contributor

Hello!

I am having some trouble getting an Arcade Expression to work and am hoping for some help! I have developed a Web App using ArcGIS Web Maps/Dashboard and Survey123. This application allows our local area hospitals to update themselves and their Diversion Status. The hospitals can put themselves on Diversion status of colors such as "Green" "Yellow" "Red" to indicate whether they can accept patients via ambulance or not. Only one hospital can be on "Red" at any given time. 

I am trying to write an expression to intersect the hospitals layer which is a hosted view of the current statuses and determine whether any of the hospitals currently have a status of Red or not. If they do it can return which hospital is "Red" and if none then "None Red". Once I can get that expression working I can pass that off to Survey123 to limit the answers the other hospitals can select from to remove red. I have tried the below expression with numerous modifications but keep getting the error "h.charAt is not a function". Can someone help me figure out what I am doing wrong?

var bufferDistance = 25; // buffer distance in miles
var bufferGeometry = Buffer($feature, bufferDistance, 'miles');
var intersectedFeatures = Intersects(bufferGeometry, FeatureSetByName($map, 'Current_Hospital_Statuses'));
var filteredFeatures = Filter(intersectedFeatures, $feature.diversionstatus == 'red');

if (Count(filteredFeatures) > 0) {
var matchingFeature = First(filteredFeatures); // get first matching feature
var name = matchingFeature['hospitalname']; // get name attribute value
return name; // return name value
}
else {
return 'None Red'; // return error message if no matches found
}

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

I think the error is in your Filter. Try this instead

var filteredFeatures = Filter(intersectedFeatures, "diversionstatus = 'red'");

 

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

I think the error is in your Filter. Try this instead

var filteredFeatures = Filter(intersectedFeatures, "diversionstatus = 'red'");

 

0 Kudos
LukeCulleny
Emerging Contributor

You sir are a genius! That worked perfectly, thank you so much for taking the time to help me! I get somewhat confused with Arcade and tried to have ChatGPT help me and it just must not know the syntax. Thank you again for the help!

0 Kudos
KenBuja
MVP Esteemed Contributor

It might be confusing if you look at the documentation for the Array Filter function (which uses a Boolean filterFunction) instead of the FeatureSet Filter function (which uses an SQL92 expression).