0

I want Extract pixel values by points from NDVI and convert it to a table in Google Earth Engine, but I don’t know what should I do.


var dataset = ee.ImageCollection('MODIS/061/MOD13Q1')
                  .filter(ee.Filter.date('2021-01-01', '2021-05-01'))
                  .mean();
var ndvi = dataset.select('NDVI');
var ndviVis = {
  min: 0.0,
  max: 8000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};

var pts = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point([-118.6010, 37.0777]), {plot_id: 1}),
  ee.Feature(ee.Geometry.Point([-118.5896, 37.0778]), {plot_id: 2}),
  ee.Feature(ee.Geometry.Point([-118.5842, 37.0805]), {plot_id: 3}),
  ee.Feature(ee.Geometry.Point([-118.5994, 37.0936]), {plot_id: 4}),
  ee.Feature(ee.Geometry.Point([-118.5861, 37.0567]), {plot_id: 5})
]);

Map.addLayer(pts);

Map.centerObject(pts);
Map.addLayer(ndvi, ndviVis, 'NDVI');

1 Answer 1

1

You can use reduceRegions to apply a reducer over the pixels that intersect with your points. As you are working with a point layer, I suggest using first reducer.

// Applying first reducer
var results = ndvi.reduceRegions({
  collection: pts, 
  reducer: ee.Reducer.first(), 
  scale: 250, // Native resolution
});

// Print in console (the NDVI value will be named “first”).  
print(results);

//Export to Google Drive as csv file
Export.table.toDrive({
  collection: results,
  description:'RasterValues',
  fileFormat: 'csv'
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.