0

I have the next code and I would like to print the pixel value summarize of "surf_refl_01" for all the collection instead to do it one image by one.

Is it possible?

The code:

// Region of interest
var region = table2;

var collection = ee.ImageCollection('MODIS/MOD13Q1')
.filterDate('2000-01-01', '2017-12-31')
.filterBounds(table2);

print(collection);

var image1 = ee.Image('MODIS/MOD13Q1/MOD13Q1_005_2000_02_18');

var clip = image1.clip(region);

var sumB3 = clip.select('sur_refl_b01').reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: table2,
  scale: 250,
  maxPixels: 1e9
});

var sumB4 = clip.select('sur_refl_b02').reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: table2,
  scale: 250,
  maxPixels: 1e9
});

Map.addLayer(clip);

print(sumB3)
print(sumB4)
1

I tweak Tyler's code a little bit..

// Region of interest
var region = ee.Geometry.Polygon(
        [[[-105.34, 40.08],
          [-105.34, 39.95],
          [-105.20, 39.95],
          [-105.20, 40.08]]]);

var collection = ee.ImageCollection('MODIS/MOD13Q1')
                   .filterDate('2000-01-01', '2017-12-31')
                   .filterBounds(region);

var ComputeRegionMean = function(img, list) {
  list = ee.List(list)
  var date = img.date().format('yyyy-MM-dd')
  var region_mean = img.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: region,
    scale: 250,
    maxPixels: 1e9
  });
  return list.add(ee.List([date, region_mean.get('sur_refl_b03')]));
};

ee.Dictionary(collection.iterate(ComputeRegionMean, ee.List([])))
var image_stats = ee.List(collection.iterate(ComputeRegionMean, ee.List([])))
var image_stats = ee.Dictionary(image_stats.flatten())
print(image_stats)
2

You can map a function across your collection that saves the region-of-interest statistic as an image property. You then can use ee.ImageCollection.aggregate_array() to convert it to a printable object.

// Region of interest
var region = ee.Geometry.Polygon(
        [[[-105.34, 40.08],
          [-105.34, 39.95],
          [-105.20, 39.95],
          [-105.20, 40.08]]]);

var collection = ee.ImageCollection('MODIS/MOD13Q1')
                   .filterDate('2000-01-01', '2017-12-31')
                   .filterBounds(region);

var ComputeRegionMean = function(img) {
  var region_mean = img.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: region,
    scale: 250,
    maxPixels: 1e9
  });
  return img.set(region_mean);
};

var image_with_stats = collection.map(ComputeRegionMean);

print(image_with_stats.aggregate_array("sur_refl_b03"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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