2

I have code that calculates NDVI and then give each image name based on the date.I want to create list after that that will contain the names-dates of each image, but I keep getting the following error message:

timeStartsNDVI.size is not a function

it's important to mention that the code works and it display my images with th e new names but doesn't create the list I want.

This is the relevant code part:

var timeStartsNDVI =filterNDVI
  .distinct('system:time_start')
  .limit(23) // Take the first 5 images
  .aggregate_array('system:time_start');

timeStartsNDVI.evaluate(function (timeStarts, error) {
  //if (error) print('Error: ' + error);
  try {
    timeStarts.forEach(function (timeStart, i) {
      var image = filterNDVI
        .filterMetadata('system:time_start', 'equals', timeStart)
        .first();
      var toexport=image.visualize(NDVIcolor).addBands(image);      
      Map.addLayer(image, NDVIcolor, new Date(timeStart).toISOString());
      //Export.image.toDrive({
        //image: toexport.toFloat(),
        //description: 'NDVI' + i,
        //scale:20,
        //crs:'EPSG:4326',
        //maxPixels:1310361348,
         // You didn't include the geometry in the script you shared.
         // I assumed it was an ee.Geometry() - if so, geometry.geometry().bounds() wouldn't work
        // region:geometry.geometry().bounds()
        //region:geometry.bounds() 
      //});
    }); 
  } catch(e) {
    print('Error: ' + e);
  }
});


//HERE I GET THE ERROR
var list=timeStartsNDVI.size();

print(list);

I have read about this error but I ca't understand why GEE will nto understand this.

This is my full code: https://code.earthengine.google.com/940fb97af1cd8a092e5a6e3448470d83

My end goal: to have list variable with al the images and their name (which is the date)

Edit: this is what I get when I print "timeStartsNDVI":

enter image description here

2

Without sharing your assets it is impossible to reproduce the error.

Most likely because you do a serverside operation that returns a ee.Object, without specifying what it is (ee.ImageCollection()) .size() will throw errors like this.

So you could try first to print timeStartsNDVI and see what type of object it returns, if you get a ImageCollection you need to define it as such: ee.ImageCollection(timeStartsNDVI). If that doesn't work you'll have to share the assets for us to reproduce your issue.

  • when I print it I get the list of the images but it doesn't really have the date, or it has the date in different form (attached image to the original post) – Reut Dec 22 '19 at 11:46
  • Can't help you if you don't share the asset or make reproducable example. The list you added is most likely dates in miliseconds. – Jobbo90 Dec 24 '19 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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