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
1 Answer 1
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.
-
thanks I t though constant was only accepting Array and numbers, I should have tried. It's mentioned in the documentation: developers.google.com/earth-engine/apidocs/ee-image-constantPierrick Rambaud– Pierrick Rambaud2023年09月18日 07:42:53 +00:00Commented Sep 18, 2023 at 7:42
Explore related questions
See similar questions with these tags.