admin管理员组

文章数量:1318570

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?

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?

Share Improve this question edited Jan 23, 2018 at 22:04 Rob 15.2k30 gold badges48 silver badges73 bronze badges asked Jan 23, 2018 at 14:14 jirikadlec2jirikadlec2 1,2761 gold badge24 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

What you see is a proxy. This is explained in the following documentation page: https://developers.google./earth-engine/client_server. Adding getInfo() fixes the error:

file_name = "my_file_" + date_string.getInfo();

https://code.earthengine.google./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./4812bb27a2869bd71771b067abd410e0

本文标签: javascriptHow do I use the quotquot operator to concatenate two stringsStack Overflow