2

I have a Sentinel 1 image collection and I want to filter the images that completely overlap my region of interest. filterBounds() keeps the images that partially overlap my ROI. While browsing the GEE documentation I found ee.Filter.contains(), however I did not understand the inputs of the function.

I tried the following but it didn't work

var imageCollection = ee.ImageCollection("COPERNICUS/S1_GRD");
var S1_filtered = imageCollection.filter(ee.Filter.contains(geometry))

Map.addLayer(S1_filtered)

where geometry is a rectangle that I drew on the map having the following coordinates:

coordinates: List (1 element)
    0: List (5 elements)
        0: [11.242486382607296,53.14196639066307]
        1: [11.720391656044796,53.14196639066307]
        2: [11.720391656044796,53.48654847659319]
        3: [11.242486382607296,53.48654847659319]
        4: [11.242486382607296,53.14196639066307]

When I run this code I obtain the following error message:

Layer 1: Layer error: String: Unable to convert object to string.

How can I use ee.Filter.contains() to filter an image collection with a polygon?

0

1 Answer 1

3

If you use positional (rather than named) arguments with ee.Filter.contains, you must pass them starting with leftField, rightValue, .... That is, the first argument is a property name, and the second argument is the value to compare with. Since you want to match against the feature's main geometry, you pass the special string '.geo' as the property name.

imageCollection.filter(ee.Filter.contains('.geo', geometry))

However, this will be quite slow, as this filter is not currently optimized like the extremely common intersection filter (filterBounds) is. So, you can improve the performance by also using filterBounds().

It will also help to choose a date range rather than requesting a mosaic of all the S1 images ever.

var imageCollection = ee.ImageCollection("COPERNICUS/S1_GRD");

var S1_filtered = imageCollection
    .filterBounds(geometry)
    .filterDate('2022-01-01', '2022-02-01')
    .filter(ee.Filter.contains('.geo', geometry));

Map.addLayer(S1_filtered);
2
  • In which situations should I use leftField + rightValue? And in which ones should I use rightField + leftValue? Sep 28, 2022 at 4:22
  • @IagoMendes You'd use them the other way around than I did if you wanted to find images completely contained within the region of interest. It's just a matter of which side of the comparison is constant and which side is taken from the feature.
    – Kevin Reid
    Sep 28, 2022 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.