2

I want to select a Landsat image collection for my area of interest and create a time series for their RGB visualization, but some image tiles are covered just a small part of the region of interest. I generate a code that compare areas for each image and just select the images which cover at least 90% of my interested area.

Here is the code, but the results are not as I expect. Some images with small coverage are still in selected image collection.

Here is the code:

function applyScaleFactors(image) {
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
  return image.addBands(opticalBands, null, true)
              .addBands(thermalBands, null, true);
}
// Landat 8 surface reflection data
var L8Coll = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
    .filterBounds(geometry).sort('DATE_ACQUIRED')
    .map(applyScaleFactors)
    .filterMetadata('CLOUD_COVER', 'less_than', 0.5)
    .map(function(image){return image.clip(geometry)});

 
print(L8Coll)

var AreaOfInterest = ee.Geometry.Polygon(geometry.coordinates())
print('Polygon area: ', AreaOfInterest.area().divide(1000 * 1000).format('%.3f'));
// to cover most of the rectangle area (90%)
var Threshould=AreaOfInterest.area().multiply(0.9).divide(1000 * 1000).format('%.3f')
var Threshould=ee.Number(Threshould)
print('Threshould',Threshould)
print('Polygon area2',geometry.area({'maxError': 1}).divide(1000 * 1000).format('%.3f'))

var listOfImages = L8Coll.toList(L8Coll.size());
print('List:',listOfImages);

var img1 = ee.Image(listOfImages.get(3));
Map.addLayer(img1,{},'listOfImages')

var f=ee.Geometry.Polygon(img1)
print('gggg',img1.geometry().area().divide(1000 * 1000).format('%.3f'))
Map.addLayer(img1.geometry())

var ImageArea = function(s) {
  var PC =ee.Image(listOfImages.get(s)).reduceRegion({
    reducer: ee.Reducer.count(),
//    scale: 30,
    maxPixels: 1E13,
  }).values().get(0);
  // We define the operation using the EE API.
  return ee.Number(PC).multiply(0.0009).format('%.1f');
};

var N=L8Coll.size().subtract(1)
print(N)
var S = ee.List.sequence(0, N);
print('S',S)

// Apply your function to each item in the list by using the map() function.
var Areas = S.map(ImageArea)//.format('%.3f');
print('Areas',Areas);  

//+++++++++++++++++++++++++++

var addTXT = function(n) {
  var l8=ee.Image(listOfImages.get(n))
  var h=Areas.get(n)
//  var t=L8CollLabel.get(n)
  var l8n = l8.copyProperties(l8)
//  .set({'Image_Label': t})
  .set({'Image_Area': h});
  return l8n
};

var L8CollLabeladed=S.map(addTXT)
print('Label Added Landsat 8:',L8CollLabeladed)

var L8CollNew=ee.ImageCollection.fromImages(L8CollLabeladed)
print('L8CollNew',L8CollNew)

print(L8CollNew.first().get('SUN_AZIMUTH').getInfo())

//++++++++++++++++++++++++++++++++++
var L8CollNewFiltered=L8CollNew.filter(ee.Filter.gte('Image_Area', Threshould))
print('L8CollNewFiltered',L8CollNewFiltered)



//++++++++++++++++++++++++++++

var compareArea = function(n) {
  var l8=ee.Image(listOfImages.get(n))
  var h=Areas.get(n)
//  var t=L8CollLabel.get(n)
  var l8n = ee.Number(l8.copyProperties(l8)
//  .set({'Image_Label': t})
  .set({'Image_Area': h}));
  return l8n
};

//+++++++++++++++++++

var L8CollNNN = L8CollNew
    .filterMetadata('Image_Area', 'greater_than',Threshould)

print(L8CollNNN)


//+++++++++++++++++++
var N=L8CollNNN.size().subtract(1)

var S = ee.List.sequence(0, N);

var ImageArea1 = function(s) {
  var PC =ee.Image(L8CollNNN.toList(L8CollNNN.size()).get(s)).reduceRegion({
    reducer: ee.Reducer.count(),
//    scale: 30,
    maxPixels: 1E13,
  }).values().get(0);
  // We define the operation using the EE API.
  return ee.Number(PC).multiply(0.0009).format('%.1f');
};
// Apply your function to each item in the list by using the map() function.
var Areas1 = S.map(ImageArea1)//.format('%.3f');
print('Areas1',Areas1);  
2
  • What is your study area? I applied your approach to var geometry = ee.Geometry.Polygon( [[[-109.031787109375, 42.341450973003425], [-109.031787109375, 42.056592054786876], [-108.680224609375, 42.056592054786876], [-108.680224609375, 42.341450973003425]]], null, false); and it works as expected.
    – xunilk
    Dec 14, 2021 at 14:03
  • coordinates are as here: 0: [29.34145846888171,41.08971838905562] 1: [29.53577914759265,41.08971838905562] 2: [29.53577914759265,41.17427709612364] 3: [29.34145846888171,41.17427709612364]... but when i apply incomplete scenes are apeared in gif by black pixels
    – Solmaz
    Dec 14, 2021 at 15:16

1 Answer 1

1

Your code works as expected. I added to it following two functions for retrieving, by another method, all and filtered areas added as property in your collections L8CollNew and L8CollNewFiltered and, values are as expected compared with the "Threshould" (Threshold?).

var allAreas = L8CollNewFiltered_lst.map(function (ele) {
  
  return ee.Image(ele).get('Image_Area');
  
});

print('allAreas', allAreas);

var filterAreas = L8CollNew_lst.map(function (ele) {
  var area = ee.Number.parse(ee.Image(ele).get('Image_Area'));
  return area.gte(ee.Number.parse(Threshould)).multiply(area);
}).removeAll([0]);

print('filterAreas', filterAreas);

Complete code is here. After running it in GEE code editor, I got result of following image.

enter image description here

AllAreas and filteredAreas lists have 51 and 40 elements; respectively. Areas in filteredAreas list are higher than Threshould value. Image placed in Map Canvas of GEE has index 0 in listOfImages list and, coincidentally, corresponds an incomplete scene.

3
  • to cover most of the rectangle area (90%) i define threshould as this: var Threshould = AreaOfInterest.area().multiply(0.9).divide(1000 * 1000).format('%.3f');
    – Solmaz
    Dec 15, 2021 at 12:47
  • so thanks for great idea.. can i get the L8 images rather than just areas (which cover most of the aoi . in fact i want to create a gif image showing the time series of RGB image in that area. in my gif the incomplete scenes are appeared . i try to remove them from gif image
    – Solmaz
    Dec 15, 2021 at 12:52
  • First comment: Yes, it is OK for areas in km2. I corroborated that. Second comment: Yes, of course. In following link you have the answer: code.earthengine.google.com/5aa26177f70ea4f82e261ccc7ccb42c7 . Last function now prints images instead areas.
    – xunilk
    Dec 15, 2021 at 13:23

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.