Select to view content in your preferred language

UPDATED: Arcade expression: Add 1 to maximum value, except if within 10m of other point

505
0
09-16-2024 06:00 PM
kawakawa4
Regular Contributor

Hello, I made a bit of a mess of my first post but I can't delete it, so have updated this one:

When creating a new point, I need it to fetch the Loc_num value from another point in the layer that is within 10m, otherwise populate it with +1 of the maximum value of all the points Loc_num field. Dropping a point within 10m of another one works fine, it fetches the Loc_num value. But when I drop a point more than 10m away from another point, it populates with 0. Here's the updated code, if anyone can tell me whats going wrong with the last bit, it would be much appreciated!

//Within 10m works but returning 0 for outside of 10m:

// Get the geometry and NamingUnit of the newly added point
var newPoint = Geometry($feature);
var newNamingUnit = $feature.NamingUnit;


// Create a 10-meter buffer around the new point
var buffered = Buffer(newPoint, 10, 'meters');

// Fetch features from the same layer that intersect with this buffer
var allNearbyFeatures = Intersects(FeatureSetByName($map, "Monitoring Devices"), buffered);




// Iterate over nearby features
for (var f in allNearbyFeatures) {
    // Check if the feature has the same NamingUnit
    if (f.NamingUnit == newNamingUnit) {
        var locNum = f.Loc_num;
    }
}
// Get the maximum Loc_num value from the nearby features
var maxLocNum = Max(allNearbyFeatures, "Loc_num");
var maxallLocNum = Max(newPoint, "Loc_num")

// Determine the new Loc_num value
if (IsEmpty(maxLocNum)) {
    return maxallLocNum + 1;
} else {
    return maxLocNum;  
}
0 Kudos
0 Replies