如何在Google Earth Engine中叠加乐队?


10

我已经在GEE中创建了一个Image集合,并且借助一个函数,我计算了NDVI索引并将其映射为以NDVI为波段创建另一个集合。

现在,我想用整个图像集合的NDVI波段创建一个堆叠图像。所以应该像NDVI_1,NDVI_2等...

我怎样才能做到这一点?我正在粘贴显示到目前为止我拥有的NDVI集合的代码

// Collection of Images 
var collection = ee.ImageCollection([feb1,feb2,Mar2,April1, April2, May1, May2, Jun1,Jun2,
July2, Aug2, Sep1, Sep2,Oct1, Oct2, Nov1, Nov2, Dec1, Dec2 ]);



//Using the following function,NDVI of the entire collection is computed
var indicesS2 = function(scene)
{ var ndvi = scene.normalizedDifference(['B8', 'B4']).rename('NDVI');
  var image = ee.Image()
                .set('system:time_start', ee.Date(scene.get('system:time_start')));
         return image.addBands([ndvi]).clip(Sheikhupura);
};
var NDVIcollection = collection.map(indicesS2);
print (NDVIcollection, 'NDVI');

Answers:



11

这是使用ee.ImageCollection.iterate()方法创建堆叠图像的示例。

我还提供了用于定义示例区域和图像集合的代码,因此这是一个有效的示例。

// Define a sample Region-of-Interest 
var roi = ee.Geometry.Polygon(
        [[[-109.1, 37.0],
          [-109.1, 36.9],
          [-108.9, 36.9],
          [-108.9, 37.0]]]);

// Define an example collection.
var collection = ee.ImageCollection('COPERNICUS/S2')
                   .filterDate('2016', '2017')
                   .filterBounds(roi);
print('collection', collection);
print('Number of images in collection:', collection.size());

// Calculate NDVI.
var calculateNDVI = function(scene) {
  // get a string representation of the date.
  var dateString = ee.Date(scene.get('system:time_start')).format('yyyy-MM-dd');
  var ndvi = scene.normalizedDifference(['B8', 'B4']);
  return ndvi.rename(dateString);
};
var NDVIcollection = collection.map(calculateNDVI);

var stackCollection = function(collection) {
  // Create an initial image.
  var first = ee.Image(collection.first()).select([]);

  // Write a function that appends a band to an image.
  var appendBands = function(image, previous) {
    return ee.Image(previous).addBands(image);
  };
  return ee.Image(collection.iterate(appendBands, first));
};
var stacked = stackCollection(NDVIcollection);
print('stacked image', stacked);

// Display the first band of the stacked image.
Map.addLayer(stacked.select(0).clip(roi), {min:0, max:0.3}, 'stacked');
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.