Hello All,
I have written a bit or arcade (I'm by no means a developer) that currently identifies features within a buffer and puts them in an array. From there I identify the Top 4 features that get pulled.
I'm struggling to 1) sort or OrderBy 'DESC' the resulting four features based on the distance (dist) and 2) limit the output to 3 decimal places.
I have attached the code below and the current result.
var intersectsLayer = Intersects(FeatureSetByName($map, "InventoryIntersects"),buff)
var devList =[]
for (var f in intersectsLayer){
var dName = f.Development_Name
var dist = DistanceGeodetic(f,$feature,'mile')
var distNum = Number(dist)
var distFull = distNum + " miles to the nearest property " + dName
Push(devList, distFull)
}
var topProps = Top(devList, 4)
return topProps
Result:
Solved! Go to Solution.
Thanks Ed and Cody. It looked like the OrderBy would break on the array but the Sort worked fine (see the last couple lines of the final code. Thanks again!!!
var buff = Buffer($feature,4,'mile')
var intersectsLayer = Intersects(FeatureSetByName($map, "InventoryIntersects"),buff)
var devList =[]
for (var f in intersectsLayer){
var dName = f.Development_Name
var dist = DistanceGeodetic(f,$feature,'mile')
var distNum = Round(Number(dist), 2)
var distFull = distNum + " miles to the nearest property " + dName
Push(devList, distFull)
}
Sort(devList)
var topProps = Top(devList, 4)
return Sort(topProps);
What happens if you do:
var topProps = Round(Top(devList, 4), 3)
Hi Ed,
I get a number: NaN message. I'm assuming the Round wants a number and devList is an array if I'm understanding of some of this. I'd like to sort on the distNum value and reduce that to a couple decimal places'
I added the Round function to the distNum var and that worked for getting the decimal places where I want them.
var distNum = Round(Number(dist), 2)
Now I just need to sort them. Almost there and thanks so far.
Hey @GregReinecke
This OrderBy function should help you out here:
var sortedList = OrderBy(devList, 'dist DESC');
For simplicity I named it sortedList, but you can rename it to devList to keep things together.
Hope that helps!
Cody
Cool that the "Round" function worked 🙂 now for arranging values in descending order have you tried the "Sort" function? Because the Sort by default arranges values in descending order.
Thanks Ed and Cody. It looked like the OrderBy would break on the array but the Sort worked fine (see the last couple lines of the final code. Thanks again!!!
var buff = Buffer($feature,4,'mile')
var intersectsLayer = Intersects(FeatureSetByName($map, "InventoryIntersects"),buff)
var devList =[]
for (var f in intersectsLayer){
var dName = f.Development_Name
var dist = DistanceGeodetic(f,$feature,'mile')
var distNum = Round(Number(dist), 2)
var distFull = distNum + " miles to the nearest property " + dName
Push(devList, distFull)
}
Sort(devList)
var topProps = Top(devList, 4)
return Sort(topProps);