It is a very simple script, but I cannot figure it out.

The script is to create a list containing the constant images from 0 to 32, and then display them.

var test = ee.List.sequence(0,32).map(function(i){return ee.Image.constant(i); });

The error is:

test: Tile error: Expected a homogeneous image collection, but an image with an incompatible band was encountered. Mismatched type for band 'constant':
Expected: Type<Float<0.0, 0.0>>.
  Actual: Type<Float<1.0, 1.0>>.
          Image ID: 1
This band might require an explicit cast.

ee.Image.constant() produces an image band whose pixel type holds exactly the number you gave it. An ImageCollection requires each image's bands to have the same types as the other images.

Therefore, you need to give the images a more general type that is the same for all of them, such as

return ee.Image.constant(i).toFloat();

to be simple, or

return ee.Image.constant(i).cast({'constant': ee.PixelType('int', 0, 31)});

to give it the type exactly wide enough.

| 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.