Select to view content in your preferred language

Arcade expression for pop up

1397
4
Jump to solution
10-30-2022 04:54 PM
Aнастасия88
Occasional Contributor

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
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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)), ',')

 

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

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), ',')
- Josh Carlson
Kendall County GIS
0 Kudos
Aнастасия88
Occasional Contributor

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?

0 Kudos
jcarlson
MVP Esteemed Contributor

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)), ',')

 

- Josh Carlson
Kendall County GIS
Aнастасия88
Occasional Contributor

Thanks a lot Josh! As a beginner, I thought OrderBy is only a function for sorting values..

0 Kudos