[GIS] Selecting every image of collection using Google Earth Engine

google-earth-engine

I am currently working on google earth engine and I have created an image collection with 15 images in it. What i want to do is to create an image for every single image in my collection. I was able to create an image for the first image of my collection by doing :

var Image1 = ee.Image(Collection.first());

Although i would like to do that for the 15 images. Is there any way to do a loop that reads the entire collection and creates images by iterating. The first one would be Image1, and then Image2, Image3 and so on…

Best Answer

I think instead of accessing the images by this syntax: list[index], you should use the get() method.

e.g.

var listOfImages = myCollection.toList(myCollection.size());
var firstImage = listOfImages.get(0)
var secondImage = listOfImages.get(1)
var lastImage = listOfImages.get(listOfImages.length().subtract(1));

// Type Cast Image for using ee.Image() function
var listOfImages = ee.Image(myCollection.toList(myCollection.size()));
var firstImage = ee.Image(listOfImages.get(0));
var secondImage = ee.Image(listOfImages.get(1));
var lastImage = ee.Image(listOfImages.get(listOfImages.length().subtract(1)));

// Now you can use ee.Image functions 
var B2 = firstImage.select("B2")
Related Question