from typing import List
from simplestac.utils import ItemCollection
[docs]
class Filter:
"""Filter allow to apply selection filters on itemCollection (simplestac) on item metadata."""
# TODO add filters docstring
def __init__(self):
self.filters: List[str] = []
[docs]
def add_filter(self, filter_string: str):
"""Add a filter string to pass to simplestac filter function.
Args:
filter_string (``str``): Filter condition.
"""
self.filters.append(filter_string)
[docs]
def filter_collection(
self, collection: ItemCollection, assets=List[str]
) -> ItemCollection:
"""Apply all filters to an ItemCollection (simplestac).
# TODO update docstrings
Args:
collection (``ItemCollection``): ItemCollection to filter.
band_adaptater (``BandAdaptater``): Band mapper of source where collection comes from.
Returns:
``ItemCollection``:
- Filtered itemCollection.
"""
filter_string = " AND ".join(self.filters) if self.filters else None
collection = collection.filter(filter=filter_string, assets=assets)
return collection
# TODO add logic to process specifics filter such as max occurence etc...
# TODO add logic to filter assets either in processor or here.