I am quite new to GEE and trying to extract the NDVI value for a set of GPS points (X, Y, and date). I have constructed my NDVI layer and am able to obtain NDVI values for my points, however the date associated with the NDVI values I extract do not correspond to the date my GPS point was obtained. In other words, I am looking to obtain the NDVI value from the date my GPS point was transmitted (or the closest date). In my GPS featureCollection I have a column 'fixtimes' formatted in dd-mm-yyyy hh:mm:ss that corresponds to the time the GPS point was transmitted.
I've attached the code I have used so far below. I suspect I will need to modify the 'date' function but am not entirely sure how.
/////////////////////////////
//// Obtain NDVI layer //////
/////////////////////////////
var filtered = L8.filterDate('2017-01-01', '2021-06-01').filterBounds(pts);
var rgb_vis = {min:0, max: 0.3, bands:['B4', 'B3', 'B2']};
var image = ee.Image(filtered.first());
function addNDVI(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']);
return image.addBands(ndvi)
}
var NDVI = addNDVI(image);
var with_ndvi = filtered.map(addNDVI);
Map.addLayer(filtered, rgb_vis, 'RGB');
Map.addLayer(NDVI, {bands: 'nd', min:0, max:1}, 'NDVI');
Map.addLayer(with_ndvi, {bands: 'nd', min:0, max:1}, 'withNDVI');
///// Function to add NDVI to GPS points /////
var ft = ee.FeatureCollection(ee.List([]));
var fill = function(img, ini) {
var inift = ee.FeatureCollection(ini)
var ft2 = img.reduceRegions(pts, ee.Reducer.first(), 30)
var date = img.date().format()
var ft3 = ft2.map(function(f){return f.set("date", date)})
return inift.merge(ft3)
};
var newft=ee.FeatureCollection(with_ndvi.iterate(fill, ft));
print(newft.first());
Output (redacted due to sensitive data) :
geometry with coordinates X and Y
properties: fixtime = 13/11/2020 ndvi band = 0.715 date = 2017-02-20 T07:40:30
I would like to get fixtime and date to correspond - and obtain the correct NDVI value for that date.