Return Last feature in a Feature Set

201
1
Jump to solution
01-05-2022 11:30 AM
Labels (1)
JimWilliams
New Contributor III

Hello,

I am looking to return the last feature in a feature set. I can do this with the first record in a feature set, but I am unsure how to return other features from the feature set. Like the second record in a feature set. 

 

 

var manholes = FeatureSetByName($datastore, 'Nodes', ['IN_1_EL'], true)
var intersecting = Intersects($feature, manholes)
var count_check = Count(intersecting)

if (count_check > 0) {
    return first(intersecting).IN_1_EL
}
else {
    return $feature.Down_Inv
}

 

 

 

Anyone know how to access the second value in a feature set?

Regards,

Jim

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

Getting the last feature is as simple as reversing the featureset's sort order and taking the first value of that. Unless otherwise specified, your featureset will be sorted by objectID ascending, so the last value would be

First(OrderBy(intersecting, 'objectid desc'))

Getting a feature at position n can be trickier, but you can do it by combining the reverse sort method with Top. By taking the top n features and then reversing the sort order, the feature at position n will be returned.

First(OrderBy(Top(intersecting, 5), 'objectid desc')) // returns fifth feature in the set

 

- Josh Carlson
Kendall County GIS

View solution in original post

1 Reply
jcarlson
MVP Honored Contributor

Getting the last feature is as simple as reversing the featureset's sort order and taking the first value of that. Unless otherwise specified, your featureset will be sorted by objectID ascending, so the last value would be

First(OrderBy(intersecting, 'objectid desc'))

Getting a feature at position n can be trickier, but you can do it by combining the reverse sort method with Top. By taking the top n features and then reversing the sort order, the feature at position n will be returned.

First(OrderBy(Top(intersecting, 5), 'objectid desc')) // returns fifth feature in the set

 

- Josh Carlson
Kendall County GIS