I calculated an image collection with the property "date". Now I want to add the property "date" as a new band but I got the error "Actual value for parameter 'id' must be a constant". Instead of .getString
I also tried .get
and .getNumber
.
// Add band:
var add_band = function(img) {
var bandDate = img.getString('Date');
return img.addBands(bandDate);
}
var new_mask = s1_mask.map(add_band);
print('ImageCollection new mask', new_mask)
And is it possible to transform the new band in a date format such as YYYY_MM_DD?
—EDIT— -> solution
var addDate = function(image){
var dateNum = ee.Image(image).date().millis()
var doyBand = ee.Image.constant(dateNum).rename('date').toFloat()
doyBand = doyBand.updateMask(image.select('VV').mask())
return image.addBands(doyBand);
};
var withDate = s1.map(addDate);
print(withDate);
Best Answer
simple answer: no. The error in your script already tells you that
.addBands()
requires a constant value so no character/string. See for example: Add a date (day of year) band to each image in a collection using Google Earth Enginehttps://code.earthengine.google.com/0013a119e3d19bf254196afd5418263b
EDIT
Sorry bit of a typo there:
You can check all your dates by retrieving the computed value from the properties (see example) or add your images and use the inquiry to see the different date bands.
https://code.earthengine.google.com/6f72be06fac2ac0b71e2815d155c2e7b