1

I'm trying to export an earth engine image to asset with an asset id that is a combination of string and number.

var assetId = 'projects/dashboard/assets/recent_mtch';  //
var ID = ee.Number(1231).format();
var assetId_imgNew = ee.String(assetId).cat(ID);
var assetId_image = 'projects/dashboard/assets/recent_mtch1231'

// This doesn't work
Export.image.toAsset({
  image: exampleImage,
  description: 'image_export',
  scale: 500,
  assetId: assetId_imgNew
});


// Somehow this works
Export.image.toAsset({
  image: exampleImage,
  description: 'image_export',
  scale: 500,
  assetId: assetId_image
});

The 'assetId_imgNew' and 'assetId_image' trigger different responses: the former failed to export with the error message: "Please provide an asset ID. Invalid JSON payload received", while the latter works.

Can you please point out what I am missing here?

1
  • 1
    As @DanielWiell answer, it's a server vs client side issue. using evaluate() would be necessary in many cases depending on what is you are dealing with. One way to figure out what are you dealing with is to print typeof() and check if it return the intended type or earth engine object. If it's object, you can use getInfo() to get it what is in there print(typeof(assetId_imgNew))// >> Object print(typeof(assetId_image)) //>> String //you can use var assetId_imgNew = assetId_imgNew.getInfo() print(typeof(assetId_imgNew)) //>> String` Commented Jul 26, 2024 at 20:49

1 Answer 1

1

assetId_image is a client-side object, while assetId_imgNew is server-side. When exporting, the assetId must be a client-side string. You can read up on server-side vs client-side here. One way to convert your asset id from server-side to client-side is to use evaluate():

assetId_imgNew.evaluate(function (assetId) {
  Export.image.toAsset({
    image: exampleImage,
    description: 'image_export',
    scale: 500,
    assetId: assetId
  })
})

https://code.earthengine.google.com/df6a54526c7c0d4132a591f0cb51a5b1

1
  • thanks for providing the solution along with the detailed background on the problems. Commented Jul 29, 2024 at 3:00

Your Answer

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.