As in the Hillshade Example, I wanted to automate adding all Layer from one Image for visual inspection.

var band_names =Image.bandNames()
  for (var i = 0; i < 4; i += 1) { 
  Map.addLayer(Image.select(ee.String(band_names.get(i))), {}, ee.String(band_names.get(i)));

This returns the longest Error ever, not gonna post it entirely enter image description here

2 Questions:

  1. the Layer name is a String:


    yields a string. What's wrong with this code?

  2. How do I call the number of Bands for the automation? I imagine something like :


You can't use a computed object for the layer name, only literal strings. You can download all of the band names from the server into a list of strings using getInfo(), and then it would work.

var band_names = Image.bandNames().getInfo()
for (var i = 0; i < 4; i += 1) { 
    Map.addLayer(Image.select(band_names[i]), {}, band_names[i]);
| improve this answer | |

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.