1

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?

3
  • can you be more precise about what you mean by "extract values"? Do you want to compute statistics (use ee.reducer) aggregating over your area of interest, or just export all values within your area of interest? Furthermore, do you want for all dates, or do also time aggregation?
    – Matifou
    Jul 13, 2018 at 22:57
  • 1
    make sure you read the guidelines for posting on StackExchange, usualyl, one would make sure to ask one question at a time, and make sure that there is no existing answer on that question.
    – Matifou
    Jul 14, 2018 at 16:23
  • Yes. I want to obtain the value of NDVI for each different polygon that it form my shapefile. Finally I would to obtain a table where: the first column is the id of my polygon, the second column the date of the image and third the value of ndvi.
    – matt85
    Jul 14, 2018 at 18:46

1 Answer 1

3

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.

3
  • Yes, you can't print more than 5000, but can always use x.limit(5) to inspect the result. Exporting won't have the limit. For the cloud, this seems to be a separate question, are you sure it has not been answered elsewhere?
    – Matifou
    Jul 14, 2018 at 16:25
  • thanks for answer! I tried the script and it give me this error message "FeatureCollection (Error) Collection query aborted after accumulating over 5000 elements". I think this error is because i ask to print in console the object is it correct? If it is possible I would like to have clarifications about the map() function. If I understand the map function is similar to a for loop cycle?.
    – matt85
    Jul 14, 2018 at 18:51
  • the code works and I managed to export a file in csv format but the file have column but not value how can I resolve this problem?
    – matt85
    Jul 17, 2018 at 10:41

Your Answer

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

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