Refine STAC query using filters

In this notebook, we demonstrate how to refine the query against the GFM STAC catalogue using the filter STAC API extension.

The filter extension references behaviour defined in the OGC API - Features - Part 3: Filtering and the Common Query Language (CQL2) and Common Query Language (CQL2) specifications.

The following queryables and combinations thereof are used:

  • Equi7Tile

  • ratio_after_blob_removal

  • flooded_pixels

  • anomaly_detected

  • sensing_date

More examples are shown here.

from pystac_client import Client

api_url = "https://stac.eodc.eu/api/v1"
eodc_catalog = Client.open(api_url)

Filter for Equi7Tile

filt = {
    "op": "eq",
    "args": [
        {"property": "Equi7Tile"}, "AS020M_E045N012T3"
    ]
}

search = eodc_catalog.search(collections="GFM", filter=filt)

print("We found", search.matched(), "items, that match our filter criteria.")
We found 3703 items, that match our filter criteria.

Filter for ratio_after_blob_removal

filt = {
    "op": "gt",
    "args": [
        {"property": "ratio_after_blob_removal"}, 0.9
    ]
}

search = eodc_catalog.search(collections="GFM", filter=filt)

print("We found", search.matched(), "items, that match our filter criteria.")
We found 113361 items, that match our filter criteria.

Filter for flooded_pixels

filt = {
    "op": "gt",
    "args": [
        {"property": "flooded_pixels"}, 5000000
    ]
}

search = eodc_catalog.search(collections="GFM", filter=filt)

print("We found", search.matched(), "items, that match our filter criteria.")
We found 27077 items, that match our filter criteria.

Filter for anomaly_detected

Currently, this property is not available, but will be added soon!

filt = {
    "op": "eq",
    "args": [
        {"property": "anomaly_detected"}, True
    ]
}

search = eodc_catalog.search(collections="GFM", filter=filt)

print("We found", search.matched(), "items, that match our filter criteria.")
We found 1103022 items, that match our filter criteria.

Combinations of queryables

filt = {
    "op": "and",
    "args": [
        {
            "op": "eq",
            "args": [
                {"property": "Equi7Tile"}, "AS020M_E045N012T3"
            ]
        },
        {
            "op": "gt",
            "args": [
                {"property": "ratio_after_blob_removal"}, 0.7
            ]
        },
    ]
}

search = eodc_catalog.search(collections="GFM", filter=filt, max_items=20)

print("We found", search.matched(), "items, that match our filter criteria.")
We found 759 items, that match our filter criteria.

List the IDs of the first 20 found items

for item in search.item_collection():
    print(item.id)
ENSEMBLE_FLOOD_20250412T232455_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250403T113821_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250331T232455_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250319T232455_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250310T113820_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250307T232454_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250226T113820_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250223T232454_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250214T113820_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250211T232454_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250130T232455_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250121T113821_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250118T232456_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250106T232457_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20250101T231647_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20241228T113733_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20241225T232458_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20241220T231648_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20241216T113824_VV_AS020M_E045N012T3
ENSEMBLE_FLOOD_20241213T232459_VV_AS020M_E045N012T3