I am using "COPERNICUS/S2" image collection for satellite imagery on Google Earth Engine using nodejs, I wanted to highlight the dates in calendar for particular month on which the image was created/loaded in dataset. Like the one working on EO Browser(see attached screenshot)

How can I get those dates with imageCollection?

enter image description here


This code will do it on the Code Editor:

var get_dates = function(collection, month, year, bounds) {
  var filtered = collection.filter(ee.Filter.calendarRange(year, year, 'year'))
                           .filter(ee.Filter.calendarRange(month, month, 'month'))

  return ee.List(filtered.toList(filtered.size()).map(function(img){
    return ee.Image(img).date().format()

var dates = get_dates(ee.ImageCollection('COPERNICUS/S2'), 1, 2017, Map.getCenter());

As I have never worked with nodejs, I don't know how to do it there, but I guess is not much different.

  • Thanks, that works like a charm in Earth Engine Code Editor! I am using nodejs(new to nodejs) to fetch those dates i dont know how i can make it work with nodejs sever side. Aug 25 '18 at 7:40
  • @rodrigo-e-principe Tried in nodejs server side and it return this instead of array { func: { signature_: { args: [Object], description: 'Map an algorithm over a list. The algorithm is expected to take an Object and return an Object.', returns: 'List', type: 'Algorithm', hidden: false, name: 'List.map' } }, args: { list: { func: [Object], args: [Object], varName: null, list_: null }, baseAlgorithm: { signature_: [Object], body_: [Object] } }, varName: null, list_: null } Aug 27 '18 at 20:54
  • @NitinMuchhadiya, as I said, I have never used nodejs, but try this: var dates = get_dates(ee.ImageCollection('COPERNICUS/S2'), 1, 2017, Map.getCenter()) and then print(dates.getInfo()) Aug 27 '18 at 22:00
  • Related: gis.stackexchange.com/questions/288614/…. There is no print() in Node.js, and the equivalent (console.log()) does not know about Earth Engine objects, so you need to call .getInfo() first. The snippet in this answer otherwise looks correct. Aug 28 '18 at 23:04
  • Thank you @DonMcCurdy! As I said I have never used nodejs, I'll modify my answer to match it. Aug 28 '18 at 23:26

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.