In an attempt to find ndvi and gndvi over a geometry containing 160 polygons, I have the following code.

var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');
var geometry = ee.FeatureCollection('projects/ypm-rs-ml/assets/plots_160');

var startDate = ee.Date.fromYMD(2016, 11, 1);
var endDate = ee.Date.fromYMD(2018, 4, 1);

function addVegIndices(image) {
  image = image.addBands(image.normalizedDifference(['B8', 'B4']).rename('ndvi'));
  image = image.addBands(image.normalizedDifference(['B8', 'B3']).rename('gndvi'));
  return image;

var originalCollection = s2
                        .filter(ee.Filter.date(startDate, endDate))
                        .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))

var viBandsOriginal = originalCollection.select(['ndvi', 'gndvi'])

var stats = viBandsOriginal.reduceRegions({
collection: geometry,
reducer: ee.Reducer.mean(),
scale: 10

If collection parameter in reduceRegions() is set to ee.Feature(geometry.toList(159).get(0)), I get the stats for the 0th polygon only. But if I want to find stats for a subset of these features say only for the first 10 features, or for features 20 to 30 in the collection, how do we do it? (Note: If this helps, each polygon has a unique property called 'poly_id' for its identification.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.