[GIS] Extract value from shapefile in Google Earth Engine

feature extractiongoogle-earth-engine

I'm new in Google Earth Engine. I want to extract the value of NDVI for a series of MODIS images using a shapefile and after export the database.
This is my script:

var vect = ee.FeatureCollection("route of shapefile");
Map.addLayer(vect);
Map.centerObject(vect,4);

//Modis collection
var poly = ee.Geometry.Polygon([
      [[15.71 , 51.403], [20.687, 51.259], [19.918, 54.614], 
      [16.007, 54.595]]]); //Interest area

var start = ee.Date('2015-03-01');
var finish = ee.Date('2018-06-01');

var modis_collection = ee.ImageCollection('MODIS/006/MOD13A1')
     .filterBounds(poly_vect)
     .filterDate(start,finish)
     .select ('NDVI');// select NDVI image

And now? I suppose I should use ee.reduce to extract the values?

Best Answer

The MODIS images are global, so that filterBounds doesn't do any good. But you extract values using reduceRegion if you want 1 value for the whole shapefile or reduceRegions() if you want it for each geometry. If you want to do that for every image in your collection, you map a function over the collection:

var results = modis_collection.map(function(image) {
  return image.reduceRegions({
     collection: vect,
     reducer: ee.Reducer.mean(),
     scale: 500
  }).map(function(feature) {
     // Add some identifying information from the image.
     return feature.set('date', image.date().format())
  })
}).flatten()

The map() will produce a collection of collections, which you then flatten() into a single table. If you want to get that out to use in another tool, you Export it as a table.