I have a FeatureCollection such as:
// Make a list of Features.
var features = [
ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi'}),
ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
];
// Create a FeatureCollection from the list
var fromList = ee.FeatureCollection(features);
How can I extract Features from the FeatureCollection using their index position within the FeatureCollection?
For example, fromList[0]
would return the Feature named "Voronoi".
Best Answer
For the first and last elements of a collection, there are shortcuts
collection.first()
andcollection.last()
.For the nth element of a collection, cast the collection to a list, then get the nth element of the list.
This would cast the first three elements of the feature collection to a list, then return the second element (zero-indexed). Allthough EarthEngine in many cases handles it automatically, to be save, recast the returned element into a feature.