1

I would like to perform a supervised classification only on the images of the collection that cover the entire geometry Domain. I used ee.Filter.contains but I get an error message in the console:

Number (Error) Filter.contains: Unable to use a collection in an algorithm that requires a feature or image. This may happen when trying to use a collection of collections where a collection of features is expected; use flatten, or map a function to convert inner collections to features. Use clipToCollection (instead of clip) to clip an image to a collection.

Help me. Here is code:

var Domain= 
    /* color: #d63000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Polygon(
                [[[-0.9131136144573282, 11.80001340655708],
                  [-0.9131136144573282, 11.44960967007124],
                  [-0.4901399816448282, 11.44960967007124],
                  [-0.4901399816448282, 11.80001340655708]]], null, false),
            {
              "system:index": "0"
            })]);


    var filtered= S2
    .filter(ee.Filter.date('2020-01-01', '2021-12-31'))
    .filter(ee.Filter.bounds(Domain))
    .filter(ee.Filter.contains('.geo', Domain))
    .map(maskS2clouds)
    .select('B.*');

1 Answer 1

1

If you want to guarantee some help in the future, you should provide a minimal functional code. Fortunately, I can guess that you are using Sentinel 2 products. Sometimes, several images in a determinate area can be truncated or rotated and this is, probably, your problem. For solving this issue with Sentinel 2 products, you can filter by using 'MGRS_TILE' property of images. Following code includes how it can be used this.

var imageVisParam = {"opacity":0.80,"bands":["B4","B3","B2"],"min":2047.736111111111,"max":5400.827586206897,"gamma":1},
    imageVisParam2 = {"opacity":0.38,"bands":["B4","B3","B2"],"min":2139.2986111111113,"max":5428.427586206896,"gamma":1},
    geometry = ee.Geometry.Polygon(
        [[[-113.57089009346218, 39.75553448647049],
          [-113.29073872627468, 39.75553448647049],
          [-113.30172505439968, 39.96636243482577],
          [-113.30172505439968, 40.13035831477493],
          [-113.54891743721218, 40.0883457054044],
          [-113.64779439033718, 39.93267349837581]]]);

var Domain = ee.Geometry.Point(-113.745, 40.16);

function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}

var S2 = ee.ImageCollection('COPERNICUS/S2_SR');

var filtered1 = S2
    .filter(ee.Filter.date('2020-01-01', '2021-12-31'))
    .filter(ee.Filter.bounds(Domain))
    .filter(ee.Filter.eq('MGRS_TILE', '11TQE'))
    //.filter(ee.Filter.contains('.geo', Domain))
    //.map(maskS2clouds)
    .select('B.*');

print(filtered1);

Map.addLayer(filtered1.mean(), imageVisParam, 'filtered1 mean');
Map.centerObject(filtered1);

var filtered2 = S2
    .filter(ee.Filter.date('2020-01-01', '2021-12-31'))
    .filter(ee.Filter.bounds(Domain))
    .filter(ee.Filter.eq('MGRS_TILE', '12TTK'))
    //.filter(ee.Filter.contains('.geo', Domain))
    //.map(maskS2clouds)
    .select('B.*');

print(filtered2);

Map.addLayer(filtered2.mean(), imageVisParam2, 'filtered2 mean');
Map.addLayer(geometry, {'color':'green'}, 'Domain');

After running above code in GEE editor, it can be observed in following picture, assuming green area is Domain, that this is not intersecting completely filtering1 mean images ('MGRS_TILE' equals '11TQE').

enter image description here

However, this situation changes in following picture filtering for 'MGRS_TILE' equals '12TTK'.

enter image description here

Concluding, complete Image Collection has 292 images in dates range between '2020-01-01' and '2021-12-31'. So, you should filter by 'MGRS_TILE' equals '12TTK' for obtaining 146 images that completely include green area.

0

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.