Hi - I'm using ArcPro 3.0.0 and I'm new to Arcade. Using Calculate Field, I trying to write a bit of Arcade code so it loops thru the values of existing field which has a string of concatenated values (i.e. -99,1,2). Where an item in this string does not equal -99, I want to append the value to a new array and then ultimately return the Mean of the NewArray. So, given -99,1,2 the resulting Mean should = 1.5
So, I've tried the following code but it doesn't work. It just returns Null values:
var NewArray = []
var OrigArray = split($feature.CONCATENATE_Story_Num, ",")
For (var i in OrigArray) {
If (i!=-99) {
NewArray+=OrigArray[i];
}
}
return Mean(NewArray)
Thanks
Solved! Go to Solution.
You're welcome! The Arcade Playground and Pro must behave a little differently under the hood, as I couldn't use mathematical functions against the array when I tested it. But I'm glad you got it to work, regardless!
Hello Everyone,
I've been trying to apply the great examples in this thread to my circumstance but keep coming up short. I want to convert the text values to number from getData function to the array. I've been trying Push and Number functions but I haven't been able to make it work.
I'm using an address point to query underlying layers, like Plats. There can be multiple Plats overlapping an address point. Ultimately, I want find the most recent Plat and append the Filename to #2 below.
The "Recorded" date field is formatted mm/dd/yyyy.
I included some commented code that I tried. Any help is appreciated. Thanks in advance!!
var getData = FeatureSetByName($datastore, "Plat", ["Filename", "Recorded"])
var PlatDataInt = Intersects(getData, $feature)
var platlist = ""
//var newarray = []
for (var k in PlatDataInt){
platlist += Right(k.Recorded, 4) + TextFormatting.NewLine
//Number(platlist[k]){
//Push(newarray, platlist[k]);
//}
}
return platlist
//return Max(platlist)
// #1 if (Val == null) return "https://mywebserver/images/survey/NoImage.pdf"
// #2 "https://mywebserver/images/survey/Plats/" + Text(Filename)
I was able to get the most recent year from the intersection plats. However, I got so head-down in this I forgot I need to pull the Filename for the most recent plat year.
var getData = FeatureSetByName($datastore, "Plat", ["Filename", "Recorded"])
var platint = Intersects(getData, $feature)
var platlist = []
for (var k in platint){
var rdate = k.Recorded
var newdate = Right(rdate, 4)
var numdate = Number(newdate, '####.')
Push(platlist, numdate)
}
var doc = Max(platlist)
return doc