In Google Earth Engine I need to generate a file name from a ee.Date object.
I have the following code in Google Earth Engine:
var date_object = ee.Date.fromYMD(2017,12, 1);
var date_string = date_object.format("YYYY-MM-dd");
print(date_string);
file_name = "my_file_" + date_string;
print(file_name);
The output of print(date_string) looks OK:
2017-12-01
But the output of print(file_name) is:
ee.String({
"type": "Invocation",
"arguments": {
"date": {
"type": "Invocation",
"arguments": {
"year": 2017,
"month": 12,
"day": 1
},
"functionName": "Date.fromYMD"
},
"format": "YYYY-MM-dd"
},
"functionName": "Date.format"
})
I expected I would get the output my_file_2017-12-01. How do I use the "+" operator with ee.String object in Google EarthEngine to concatenate two strings?
What you see is a proxy. This is explained in the following documentation page: https://developers.google.com/earth-engine/client_server. Adding getInfo() fixes the error:
file_name = "my_file_" + date_string.getInfo();
https://code.earthengine.google.com/e61868ab3f333e8f2d19afd96b396964
And for the server-side EE code, as suggested by Nick:
file_name = ee.String('my_file_').cat(date_string);
https://code.earthengine.google.com/4812bb27a2869bd71771b067abd410e0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With