Return all values inside buffer using arcade

505
1
02-14-2023 11:39 AM
anonymous55
Occasional Contributor II

Hello

I have this code which sort values base on buffer 1320 feet and return First values. I want to return all values inside the buffer not just one. is it any way I can do this? 

Thanks

 

// If the feature doesn't have a geometry, return null
if (IsEmpty(Geometry($feature))) { return null }
// Get the bus stops layer
// To customize, replace the layer name below
var busStops = FeatureSetByName($map,"RTD Active Bus Stops")
// Buffer the current location and intersect with the bus stops
var bufferedLocation = Buffer($feature, 1000, 'feet')
var candidateStops = Intersects(busStops, bufferedLocation)
// Calculate the distance between the bus stops and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateStops) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}
// Sort the candidate bus stops by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest bus stop
var closestFeatureWithDistance = First(sorted)
// If there was no bus stop, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the bus stop name attribute value
// To customize, replace the field name "STOPNAME" below
return `${closestFeatureWithDistance['feature']['STOPNAME']}`

 

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

To return all the values for the features in the buffer, you have to loop through the sorted FeatureSet and extract the value from each feature. You can add each of the values into an array, then return the concatenated result.

var output= [];
for (var f in sorted){
  Push(output, f.STOPNAME)
}
return Concatenate(output,`/n`);