2

I started with GoogleEngine recently and I was wondering how I can display all images of my collection as layers. I guess there is a better way than manually copy past / typing:

 var img1 = ee.Image('COPERNICUS/.....);
 var img2 = ....;
 var imgx = ....

 Map.addLayer (img1);
 Map.addLayer(img2);
 Map.addLayer(imgx)....

This questions was already asked in 2017 but I was unable to retrace the link/shared google group...

  • Displaying a lot of layers simultaneously would take a lot of time. – Dmitri Chubarov May 30 '18 at 11:05
  • My images are clipped, and since I can manually display 15 images, I guess "the time it takes" is not the problem... I',m just looking for an auto-way – Andreas Eugster May 30 '18 at 15:49
3

If you are only displaying a reasonable amount of images you can use a client-side function to add each image as a layer to the map.

Here's an example using 15 images in a polygon you would draw and rename roi.

var s2 = ee.ImageCollection("COPERNICUS/S2")
  .filterBounds(roi)
  .select("B2")
  .limit(15)

function addImage(image) { // display each image in collection
  var id = image.id
  var image = ee.Image(image.id)
  Map.addLayer(image)
}

s2.evaluate(function(s2) {  // use map on client-side
  s2.features.map(addImage)
})
2

In addition to the answer of Kersten, you could also add this piece of code to easily view all the images by moving a slider:

var slider = ui.Slider();
slider.onSlide(function(value) {
  var int_value = value * (Map.layers().length() - 1) >> 0;
  Map.layers().get(int_value).setOpacity(1);
  for (var i = int_value + 1; i < Map.layers().length(); i++) {
    Map.layers().get(i).setOpacity(0);
}
});
print(slider);

It does this by changing the opacity of each layer.

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.