Hello, I am seeking an advice for an Arcade expression for pop up in Map Viewer. What I would like to show in a field of pop up is, which features of Polygon class A are within the buffer feature of Polygon class B. To show that, the code does extracting attributes from Polygon feature A (Regional Area) that intersects with Polygon feature B (Buffer), and then populating the extracted attributes in a field of Polygon B. Also, when populating the attribute in the field, I would like to delete any duplicates of the extracted attributes and concatenate them with comma.
I kind of managed to prepare an expression for extracting values and concatenate them (see code below) but I am still new to Arcade, I have not found the way of deleting duplicate values and concatenate them with comma. i.e., current return includes all the duplicated values and concatenated (e.g. 1117111511131317) but I want to make it like (e.g. 11,13,15,17).
Thanks in advance for any Arcade expression solutions!
var fsReArea = FeatureSetByName($datastore, "Regional_Area", ["*"], false)
var fsReAreaIntersect = Intersects(fsReArea, Geometry($feature))
var orderRA = OrderBy(fsReAreaIntersect, "objectid ASC")
var arr = ""
for(var regionA in orderRA) {
if(regionA.Region_Code != null) {
arr += concatenate(regionA.Region_Code)
}
}
return arr
Solved! Go to Solution.
Fortunately, there's another array function, Sort. Given an array of numeric values, it will by default sort them ascending.
return Concatenate(Sort(Distinct(arr)), ',')
You'll have better luck working with an array. In your loop, use Push to add codes to an array.
Once you have an array with your values, you can simply use Distinct to remove duplicates.
Once you have your array of distinct values, use Concatenate to create a comma-delimited string.
var fsReArea = FeatureSetByName($datastore, "Regional_Area", ["*"], false)
var fsReAreaIntersect = Intersects(fsReArea, Geometry($feature))
var orderRA = OrderBy(fsReAreaIntersect, "objectid ASC")
var arr = []
for(var regionA in orderRA) {
if(regionA.Region_Code != null) {
Push(arr, regionA.Region_Code)
}
}
return Concatenate(Distinct(arr), ',')
Thanks Josh for your help!
The return (11,17,13,15) is nearly what I wanted but I wanted the return in order like (11,13,15,17). As Region_code is text field, I updated the code like this:
var fsReAreaIntersect = Number(Intersects(fsReArea, Geometry($feature)))
var orderRA = OrderBy(fsReAreaIntersect, "Region_Code ASC").
But this did not work unfortunately. Is there any way of arranging the return values in order?
Fortunately, there's another array function, Sort. Given an array of numeric values, it will by default sort them ascending.
return Concatenate(Sort(Distinct(arr)), ',')
Thanks a lot Josh! As a beginner, I thought OrderBy is only a function for sorting values..