0

I get values as a list from another computation and I would like to create an ee.Image with 1 band for each value.

I wanted to do it as specified in the documentation:

var list = ee.List([1,2,3])
var image = ee.Image(list)
var buffer = geometry.buffer(1)
var values = image.reduceRegion(ee.Reducer.first(), buffer, 1)
print(values)

but I get the following error:

A mapped function's arguments cannot be used in client-side operations

If I use the getInfo() method on list it works but I would like to avoid client side operation, is there another way ?

Here is the example with the point geometry: https://code.earthengine.google.com/11a69463743086cf20709ab359d8289c

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Sep 17, 2023 at 18:26

1 Answer 1

0

To instantiate a multi-band constant image using an ee.List, you'll need to use ee.Image.constant instead of ee.Image.

var list = ee.List([1,2,3]);
var image = ee.Image.constant(list); // Works!
var bad_image = ee.Image(list); // Doesn't work :(

I suspect this is unintended behavior since the ee.Image constructor works as a shortcut for creating constant images in most cases including with client-side lists, but it's an easy workaround at least.

answered Sep 18, 2023 at 1:37
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.