3

I'm calculating the EVI of the COPERNICUS/S2 Sentinel-2 dataset on Google Earth Engine. I'm testing exporting my results, and want to view particular images in my processed ImageCollection (called evi2week below). I want to view the second image in evi2week, but don't know how to select it while including all of my EVI calculations instead of the raw COPERNICUS/S2 image. How do I select this second image and all of its bands to add to the map?

//get 2016 dataset
var collection2016= ee.ImageCollection('COPERNICUS/S2')
            .filterBounds(studyarea)
                  .filterDate('2016-01-01', '2016-12-31')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',50));
print('Collection 2016', collection2016);

// make EVI expression into a function
var addEVI=function(image){
var EVI = image.expression(
      '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
      'NIR' : image.select('B8').divide(10000),
      'RED' : image.select('B4').divide(10000),
      'BLUE': image.select('B2').divide(10000)}).rename('EVI');
      return image.addBands(EVI);
};

//map EVI across 2016 dataset
var calculated2016=collection2016.map(addEVI);
print('calculated 2016', calculated2016);

//mapping selecting only EVI band across 2016 dataset
var evi2016 =calculated2016.select('EVI');
print('evi 2016', evi2016);

//making two week period collection to export
var evi2week= evi2016.filterDate('2016-07-01', '2016-07-14');

2 Answers 2

7

Quick and dirty way to do this would be to change the image collection to a list of images and then use get() to select the image that you want:

var evi2weekList=ee.ImageCollection(evi2week).toList(999);
var evi2week2ndImage=ee.Image(ee.List(evi2weekList).get(1)); //note index 0 is the first image

print('2ndImage from evi2week imColl',evi2week2ndImage)

Hope that helps :)

3

Another way of doing that is to convert your ImageCollection to an Image with multiple bands. Then, you can extract the band names, get the second name (index 1) and use getInfo to convert the band name to a client side object. An advantage of using this approach is that the image can be easily exported.

// Convert image collection to a single image with a lot of bands
var evi2weekList=ee.ImageCollection(evi2week).toBands();
// Get the band names
var bandNames = evi2weekList.bandNames();
// Add layer calling the second bandName
Map.addLayer(evi2weekList, {bands: bandNames.get(1).getInfo()}, 'bands');

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.