1

I have filtered Sentinel 2 images to get suitable cloud free images from the time period I require, however I cannot figure out how to extract the date from the images, but with my current code I get the error:

Date (Error) Date: Parameter 'value' is required.

//  Define the image collection 
var image = ee.ImageCollection(sent2
// filter to get only images in the date range we are interested in
    .filterDate("2018-05-01", "2018-07-30")
// filter by polygon
    .filterBounds(tiwi))
// sort the collection by cloud cover 
    .sort("CLOUD_COVERAGE_ASSESSMENT")
// select the first image i.e. the most cloud free image in the date range
    .min();

// print the image to the console.
    print("A Sentinel-2 scene:", image);


  // Define visualization parameters in a JavaScript dictionary for true colour rendering. Bands 4,3 and 2 needed for RGB.
    var trueColour = {
        bands: ["B4", "B3", "B2"],
        min: 0,
        max: 3000
        };

  // Add the image to the map, using the visualization parameters.
  Map.addLayer(image, trueColour, "true-colour image");

// Get the timestamp and convert it to a date.
var date = ee.Date(image.get('system:time_start'));
print('Timestamp: ', date);
1
  • 1
    It looks like the reasoning this code doesn't work is perhaps because there has been more than one image generated. Can anyone tell me how to adapt this code to extract dates for multiple images, or which function to use instead? Oct 13, 2019 at 7:25

1 Answer 1

1

Your problem lies elsewhere.

when you use .min() Reduces an image collection by calculating the minimum value of each pixel across the stack of all matching bands..

This does not find the image with the lowest "CLOUD_COVERAGE_ASSESSMENT"

Your code is nearly there, as in the .sort() you put the collection in order of your cloud coverage.

Just change your .min() to .first() and your code will work.

//  Define the image collection 
var image = ee.ImageCollection(sent2
// filter to get only images in the date range we are interested in
    .filterDate("2018-05-01", "2018-07-30")
// filter by polygon
    .filterBounds(tiwi))
// sort the collection by cloud cover 
    .sort("CLOUD_COVERAGE_ASSESSMENT")
// select the first image i.e. the most cloud free image in the date range
    .first();  // previously => .min();

Now you will have only one image and it will no longer be a collection. Your date parameter should work fine now.

======= to find the date of each image of the collection is a different question.

1
  • 1
    I see now that your question is actually related to this previous question. gis.stackexchange.com/questions/333288/… Which is different to what I suggested in my answer, because you are looking for the min() value pixel to create cloud free mosaic. As a result, you lose the metadata of the original images, as each pixel could come from a different image... Oct 13, 2019 at 12:36

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.