I have a shapefile with several fields, corresponding to different wheat fields of a certain year. Using as Input an image collection converted to NDVIs, I would like to calculate the mean NDVI value for each field for every available date. Then, export the raster of the maximum "mean value" of each field. The key here is not to do a pixel-wise maximum NDVI selection, but by FIELD.
In other words, I need to get the Sentinel-2 NDVI image from a field that corresponds to the highest mean NDVI value (of the field polygon) registered within a time period. This is not the max() function over a ImageCollection (which synthesizes a image with pixels from different dates). I need the image of a REAL scene, which actually happened at one DATE.
var geometry = /* color: #d63000 */ee.FeatureCollection(
[ee.Feature(
ee.Geometry.Polygon(
[[[-61.58584513408002, -35.77369642524422],
[-61.58035197001752, -35.778222714936696],
[-61.5727130387431, -35.772373307284425],
[-61.56704821330365, -35.77683003785912],
[-61.55262865763959, -35.76506094262748],
[-61.5643016312724, -35.75586730183619],
[-61.58472933512982, -35.77286077435719]]]),
{
"system:index": "0"
}),
ee.Feature(
ee.Geometry.Polygon(
[[[-60.64656168176598, -35.72030669380027],
[-60.62716394617028, -35.70358079489495],
[-60.645703374881215, -35.68963986472292],
[-60.652913152713246, -35.69214941201044],
[-60.66733270837731, -35.70427777742714]]]),
{
"system:index": "1"
})]);
Map.addLayer(geometry,{},'ROIs')
function getNDVI10 (image){
return image.normalizedDifference(['B8','B4'])
.select([0],['NDVI'])
.addBands(image.metadata('system:time_start').rename('DATE'))
}
function getStats (image){
return image.select(['NDVI']).reduceRegions({collection: geometry,reducer: ee.Reducer.mean(),scale: 10,
})}
var nbrParams = {min: 0.4, max: 0.8, 'palette': ['red','yellow','green']};
var s2 = ee.ImageCollection("COPERNICUS/S2")
.filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 5))
.filterBounds(geometry);
var NDVI10_2017 = s2.filterDate('2017-10-01','2017-12-01').map(getNDVI10)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
var NDVIpixel_2017 = NDVI10_2017.qualityMosaic('NDVI').clip(geometry)
Map.addLayer(NDVIpixel_2017.select(['NDVI']),{}, "maxNDVI S2",true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
var NDVI10_2017_stats = NDVI10_2017.map(getStats)