如何使用“+”运算符连接两个字符串?
How do I use the "+" operator to concatenate two strings?
在 Google Earth Engine 中,我需要从 ee.Date
对象生成文件名。
我在 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);
print(date_string)
的输出看起来不错:
2017-12-01
但是 print(file_name) 的输出是:
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"
})
我预计我会得到输出 my_file_2017-12-01
。如何在 Google EarthEngine 中将“+”运算符与 ee.String
对象一起使用来连接两个字符串?
你看到的是代理。这在以下文档页面中进行了解释:https://developers.google.com/earth-engine/client_server。添加 getInfo() 修复错误:
file_name = "my_file_" + date_string.getInfo();
https://code.earthengine.google.com/e61868ab3f333e8f2d19afd96b396964
对于服务器端 EE 代码,正如 Nick 所建议的:
file_name = ee.String('my_file_').cat(date_string);
https://code.earthengine.google.com/4812bb27a2869bd71771b067abd410e0
在 Google Earth Engine 中,我需要从 ee.Date
对象生成文件名。
我在 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);
print(date_string)
的输出看起来不错:
2017-12-01
但是 print(file_name) 的输出是:
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"
})
我预计我会得到输出 my_file_2017-12-01
。如何在 Google EarthEngine 中将“+”运算符与 ee.String
对象一起使用来连接两个字符串?
你看到的是代理。这在以下文档页面中进行了解释:https://developers.google.com/earth-engine/client_server。添加 getInfo() 修复错误:
file_name = "my_file_" + date_string.getInfo();
https://code.earthengine.google.com/e61868ab3f333e8f2d19afd96b396964
对于服务器端 EE 代码,正如 Nick 所建议的:
file_name = ee.String('my_file_').cat(date_string);
https://code.earthengine.google.com/4812bb27a2869bd71771b067abd410e0