I have a CSV file that has 30 years of annual data that relates to my ROI. For the analysis I am doing, I want to turn this CSV file into an ImageCollection with each image being a single year having the the constant value from that year in each pixel of my roi. I could make a single image as follows:

var image = ee.Image.constant(5.5)//or whatever value

I could manually make each image and create an ImageCollection from them but I would like to automate the process or write a function so I can do this for various climate data files. Is there a way to do this? I currently use the JavaScript API.

1 Answer 1


You just need to make it into a function to apply to each feature in your table (FeatureCollection). The function should return an ee.Image, and when you map it to your table, make it into an ee.ImageCollection:

var imageCollection = ee.ImageCollection(
    return ee.Image(
    .addBands(ee.Image(ee.Number(feature.get("year"))).rename("year")) // year as a band.
    .set({year:feature.get("year")})  // year as a property 

I also added the option to set the "year" as a property, which might be useful instead of having it as an additional band.

Example using 10 random values from 2011 to 2020 (10 years):


  • Thanks! This worked great. The only change I needed to make for my specific table was to explicitly cast the value and year bands, i.e. .cast({'value': ee.PixelType('float', -31, 31)})
    – rebeccalm
    Commented Jun 12, 2023 at 20:19

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.