Google Earth Engine – Filtering Images That Completely Overlap Area of Interest

filtergoogle-earth-engine

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?

Best Answer

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);