0

There are four tiles (path:41,row:35/path:41,row:36/path:42,row:35/path:42,row:36) of LANDSAT 8 surface reflectance that cover my study area. I want to remove only images(tile) with path 42 and row 36 from this collection. How can I do that? Here is my code:

Map.centerObject(table);
Map.addLayer(table);

var sd = '2015-01-01';//Start Date
var ed = '2016-01-01';//End   Date

var suro = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(table)
.filterDate(sd,ed)
//.filter(ee.Filter.and(ee.Filter.notEquals('WRS_PATH',42),ee.Filter.notEquals('WRS_ROW',36)))
.filter(ee.Filter.lt('CLOUD_COVER', 45));

var sur = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(table)
.filterDate(sd,ed)
//.filter(ee.Filter.and(ee.Filter.notEquals('WRS_PATH',42),ee.Filter.notEquals('WRS_ROW',36)))
.filter(ee.Filter.lt('CLOUD_COVER', 45))
//Map a function to mask clouds and negative values
.map(function(img){
  var idd = img.id();
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = 1 << 3;
  var cloudsBitMask = 1 << 5;
  // Get the pixel QA band.
  var qa = img.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  // Return the masked image, scaled to reflectance, without the QA bands.
  var img2 = img.updateMask(mask).multiply(0.0001).select("B1").rename(idd);
  //Mask negative values from images
  var mask2 = img2.gt(0);
  return img2.multiply(mask2);
})
.toBands()
.clip(table);
Map.addLayer(sur);

var imColl_sur = sur.getInfo().bands;
print(imColl_sur);
print(imColl_sur.length);

for (var i = 0; i < imColl_sur.length; i++) {
  //Image Load
  var im = sur.select(imColl_sur[i]["id"]);
  //var id = imColl_sur[i]["id"];
  //var im = ee.Image.load(id);
  //Image Properties from original collection
  var idl = suro.getInfo().features[i]["properties"]["LANDSAT_ID"];
  var st = suro.getInfo().features[i]["properties"]["SENSING_TIME"];
  var sza = (suro.getInfo().features[i]["properties"]["SOLAR_ZENITH_ANGLE"])
    .toString();
  //Download
  Export.image.toDrive({
    image: im,
    description: 'L8_surReflectance_B1_'+idl.slice(10,26)
      +st.slice(11,13)+st.slice(14,16)+'_'
      +sza.slice(0,2)+sza.slice(3,8),
    scale: 30,
    region: table,
    maxPixels: 1e9
  });
}
7th storm
  • 41
  • 1
  • 9

1 Answers1

0

Edit:

Combining filters probably works somehow, and would be more elegant.

But you can use a second approach: create a new metadata variable combining ROW and PATH, and filter based on it:

var geometry = ee.Geometry({"type":"Polygon","coordinates":[[[-98.01249999999999,41.430123208731864],[-98.01249999999999,38.809492348693325],[-92.03593749999999,38.809492348693325],[-92.03593749999999,41.430123208731864]]],"geodesic":false,"evenOdd":true})

var sd = '2015-01-01';//Start Date
var ed = '2016-01-01';//End   Date

var suro = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(geometry)
.filterDate(sd,ed)
.map(function(image){
  return image.set({'WRS_PATHROW':{'path':image.get('WRS_PATH'),
                          'row':image.get('WRS_ROW')}
})})
.filter(ee.Filter.neq('WRS_PATHROW',  {'path':25, 'row':32}))

You can combine two filters with an ee.Filter.and to remove any images that have WRS_PATH=21 and WRS_ROW=32:

var filters =  ee.Filter.and(
  ee.Filter.neq('WRS_PATH',21),
  ee.Filter.neq('WRS_ROW',32)
);

var suro = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(geometry)
.filterDate(sd,ed)
.filter(filters);
Community
  • 1
  • 1
Val
  • 6,585
  • 5
  • 22
  • 52
  • But this filter removes all images that have path=21 or row=32. I don't want images for example that have path = 21 and row= 34 been removed. – 7th storm Jan 29 '20 at 12:11
  • Let's assume there is a pair like (path,row) and there are two values for path and two values for row. so we have four pairs with available values. (41,35), (41,36), (42,35) and (42,36). I need a filter that remove only the last pair. the filter that you proposed will remove the second and third pair too. – 7th storm Jan 29 '20 at 12:34
  • @7thstorm yeah sorry, was a bit too fast with my approach. Updated a working solution. – Val Jan 29 '20 at 12:54