0

I want to filter and select particular images in a collection in Google Earth Engine?

var l51990 = ee.ImageCollection('LANDSAT/LT5_L1T_TOA')
.filterBounds(table)   
.filterDate('1990-01-01','2013-01-01')  
.sort('CLOUD_COVER');

I would like to select the image with least cloud cover per year from 1990 to 2013.

Is there a clean way to do this without repeating that block of code, over and over?

4 Answers4

0

You can use first() to get the image or mosaic() to get the pixels.

0

Is there a clean way to do this without repeating that block of code, over and over?

Yes - use a for or while loop to iterate through the same block of code as many times as you need. Use variables within the loop to determine the bounds, date and sort options (possibly also including the lat and long values)

I won't write a working piece of code FOR you, but I will help you if you post your own.

Mark
  • 691
  • 7
  • 20
0

You should do the temporal filtering for each year within a mapped function over a list of the years you want the least cloudy image from. Do the spatial filtering first outside of the mapping function and you then perform the filtering and grab the first image within the function. This will result in an image collection with the least cloudy images from each year over your study area.

var years = ee.List.sequence(1990,2013)
var l5 = ee.ImageCollection('LANDSAT/LT5_L1T_TOA').filterBounds(table)

var leastCloudy = ee.ImageCollection(years.map(function(i){
    var t1 = ee.Date.fromYMD(i,1,1)
    var t2 = t1.advance(1,'year')
    return ee.Image(l5.filterDate(t1,t2).sort('CLOUD_COVER').first())
}))

print(leastCloudy)

Once you have your filtered image collection you can then perform whatever analysis on that.

Kel Markert
  • 807
  • 4
  • 12
0

You can use first() for ee.ImageCollection to get the first image of that, OR use .mosaic() to composite all the images in a collection to one image. More ways to convert image collections to images are: median(), mean(), and.... (Make sure you use the right command depending on your work) OR you can use print(l51990) then see images of the collection in a console part and select one of them handly.

BUT for cloud cover filtering on collection, use lt filter:

var l51990 = ee.ImageCollection('LANDSAT/LT5_L1T_TOA')
.filterBounds(table)   
.filterDate('1990-01-01','2013-01-01')
.filter(ee.Filter.lt("CLOUD_COVER", 10))

this LT filter gives you images with less than 10% cloud cover

gloo
  • 681
  • 2
  • 12
Mr. Holy
  • 1
  • 3