1

I'm trying to generate a table with my GNDVI points value from a time series. I have a feature collection of my polygons, another feature collection of my random points in the polygons. I have a image collection as well and I want a table with the points value in every polygon for every date in the time series. I joined the two feature collections and I don't know how to proceed from here.

How do I do that?

my code:

var fc = ee.FeatureCollection(user_account+folder+shpfile_name);
var S2 = ee.ImageCollection(image_collection)
        .filterDate(first_date, last_date)
        .filterBounds(fc)
        .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 18);

//-----------------------------------------------------------------------------------
print(S2)
print(fc)           // CRS must be WGS84 (for the shapefile)          

//-----------------------------------------------------------------------------------
//Image Expression for calculating GNDVI----------------------------------------------
var band_1 = 'B3'
var band_2 = 'B8'

var addGNDVI = function(image) {
  var GNDVI = image.expression(
  '(B8-B3)/(B8+B3)',
  {
    'B3': image.select('B3'),
    'B8': image.select('B8'),

  }).rename('GNDVI');
  //NDVI index
  return image.addBands(GNDVI.add(ee.Image(0.0)));
  //Add 0.0 value to GNDVI (currently not in use)
};
var t = ee.FeatureCollection.randomPoints(fc, 100)
print(t)
Map.addLayer(t)

// Calculate GNDVIfor images in the Image collection 
var S2_withGNDVI = ee.ImageCollection(S2).map(addGNDVI);          
print(S2_withGNDVI)


// Show image of mean GNDVI (over image collection) on GEE. 
var scene = ee.Image(S2_withGNDVI.mean());

// Prepare palette for image display     
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
          '74A901', '66A000', '529400', '3E8601', '207401', '056201',
          '004C00', '023B01', '012E01', '011D01', '011301'];
          //palette for GNDVI image on GEE.

// Add GNDVI image and shapefile on GEE platform (min;max are range values)
Map.addLayer(scene.select('GNDVI'), {min: min_v, max: max_v, palette: palette}, 'GNDVI', 1, 0.85);
Map.addLayer(fc.style({color: 'e02406', fillColor: '00000000'}));    

//Export GNDVI Time Series into a Scatter Chart and a CSV format              
var TimeSeries = Chart.image.seriesByRegion(
S2_withGNDVI, fc, ee.Reducer.mean(), 'GNDVI', 3, 'system:time_start', fc_ID)
    .setChartType('ScatterChart')
    .setOptions({
      title: 'GNDVI Time Series For Shift 1-2 Argentina',
      vAxis: {title: 'GNDVI'},
      hAxis: {title: 'Date'},
      lineWidth: 1,
      pointSize: 4,
      series: {
}});
// Display.
print(TimeSeries); 

// Define a spatial filter as geometries that intersect.
var spatialFilter = ee.Filter.intersects({
  leftField: '.geo',
  rightField: '.geo',
  maxError: 1
    });
    print(spatialFilter)

// Define a save all join.
var saveAllJoin = ee.Join.saveAll({
  matchesKey: 'points',
});
print(saveAllJoin)

// Apply the join.
var intersectJoined = saveAllJoin.apply(fc, t, spatialFilter);
print(intersectJoined)

0

Your Answer

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