Based on the answer here: How to set multiple values in list in Google Earth Engine?

I'm trying to change the property of images in a list that had been an image collection before converting to list.

The code here creates a new image collection and the new collection gets extremely large values in the system:index, making the collection very unwieldy. I want to merge the new collection with the old one and I can't do anything with the new collection because of the system:index

var date = '2022-06-01'
var humidityThreshold = 90 

var collection = ee.ImageCollection("NOAA/GFS0P25")
  .filter(ee.Filter.eq('creation_time', ee.Date(date).millis())) // replace forecast with creation
  .map(function (image) {
    return image
      .copyProperties(image, image.propertyNames())
var counts = ee.ImageCollection(collection.iterate(
  function (image, acc) {
    image = ee.Image(image)
    acc = ee.ImageCollection(acc)
    var last = ee.Image(acc.get('last'))
    var count = last.add(1)
      .where(image.not(), ee.Image(0))
    return acc.merge(ee.ImageCollection([count]))
      .set('last', count)
    .set('last', ee.Image(0))

// This is my attempt based on suggestion from the answer linked at start of this post.
var coun2 = counts.toList(counts.size());


var coun3 = coun2.map(function(image) {
  return image.set('system:index', 

The var coun3 returns this message:

Line 35: image.getString is not a function


1 Answer 1


When you iterate over a list, you have to cast each element, as opposed to when iterating an image or feature collection.

var coun3 = coun2.map(function(image) {
  image = ee.Image(image)
  return image.set('system:index', 

That said, you typically want to avoid turning collections into lists. It requires the whole collection to be loaded into memory, and you can get errors for larger collections. If you don't like the values in system:index, you could always add a separate property.

  • Thanks, Daniel. The script works partly. I don't get the error, but it doesn't replace the system:index value. The first image's index has 420 characters and it gets longer from there. I want to either make the index a "normal" length value, like 15 or something characters, or get rid of it. I had planned to use the index as the property to do a merge with the starting collection. If I
    – John Polo
    Nov 21, 2022 at 14:45
  • You're original question was how to set a property inside a list, and this is how to do that. Now, your problem is that your replacement expression doesn't matching anything. I will also stress again that you'll almost certainly be better off using a different property for what you're trying to do, not an internal one that EE might mess with. Nov 21, 2022 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.