Exemple #1
0
def get_filter_fes(filters, logical_operator=And):
    """Create filter encoding specification (OGC FES) object based on given
    filters

    :param Tupple.<dict> filters: tupple of filters
    :param logical_operator: owslib.fes.And or owslib.fes.Or
    :return: filter encoding specification
    :rtype: owslib.fes.AND
    """

    conditions = []
    filter_request = None

    for myfilter in filters:
        value = myfilter['value']
        if myfilter['operator'] == '=':
            conditions.append(PropertyIsEqualTo(myfilter['attribute'], value))
        elif myfilter['operator'] == '!=':
            conditions.append(
                PropertyIsNotEqualTo(myfilter['attribute'], value))
        elif myfilter['operator'] == '~':
            conditions.append(PropertyIsLike(myfilter['attribute'], value))
        elif myfilter['operator'] == '>':
            conditions.append(
                PropertyIsGreaterThan(myfilter['attribute'], value))
        elif myfilter['operator'] == '>=':
            conditions.append(
                PropertyIsGreaterThanOrEqualTo(myfilter['attribute'], value))
        elif myfilter['operator'] == '<':
            conditions.append(PropertyIsLessThan(myfilter['attribute'], value))
        elif myfilter['operator'] == '<=':
            conditions.append(
                PropertyIsLessThanOrEqualTo(myfilter['attribute'], value))
        elif myfilter['operator'] == 'BETWEEN':
            conditions.append(
                PropertyIsBetween(myfilter['attribute'], *value.split(',')))
        elif myfilter['operator'] == 'BBOX':
            bbox_filter = BBox(myfilter['value'], 'EPSG:3857')
            conditions.append(bbox_filter)
        elif myfilter['operator'] == 'IN':
            new_filters = [{
                'value': value,
                'operator': '=',
                'attribute': myfilter['attribute']}\
                        for value in value.split(',')]
            conditions.append(get_filter_fes(new_filters, logical_operator=Or))

    if len(conditions) > 1:
        filter_request = logical_operator(conditions)
    else:
        filter_request = conditions[0]

    return filter_request
Exemple #2
0
    def __convert_query_params(self, product_type_def, product_type, params):
        """Translates eodag search to CSW constraints using owslib constraint classes"""
        constraints = []
        # How the match should be performed (fuzzy, prefix, postfix or exact).
        # defaults to fuzzy
        pt_tag, matching = (
            product_type_def["name"],
            product_type_def.get("matching", "fuzzy"),
        )
        if matching == "prefix":
            constraints.append(
                PropertyIsLike(pt_tag, "{}%".format(product_type)))
        elif matching == "postfix":
            constraints.append(
                PropertyIsLike(pt_tag, "%{}".format(product_type)))
        elif matching == "exact":
            constraints.append(PropertyIsEqualTo(pt_tag, product_type))
        else:  # unknown matching is considered to be equal to 'fuzzy'
            constraints.append(
                PropertyIsLike(pt_tag, "%{}%".format(product_type)))

        # footprint
        fp = params.get("geometry")
        if fp:
            constraints.append(
                BBox([fp["lonmin"], fp["latmin"], fp["lonmax"], fp["latmax"]]))

        # dates
        start, end = (
            params.get("startTimeFromAscendingNode"),
            params.get("completionTimeFromAscendingNode"),
        )
        if start and "date_tags" in self.config.search_definition:
            constraints.append(
                PropertyIsGreaterThanOrEqualTo(
                    self.config.search_definition["date_tags"]["start"],
                    start))
        if end and "date_tags" in self.config.search_definition:
            constraints.append(
                PropertyIsLessThanOrEqualTo(
                    self.config.search_definition["date_tags"]["end"], end))
        return [constraints] if len(constraints) > 1 else constraints
Exemple #3
0
 def filter_comp_less_than_or_equal_to(self, **kwargs):
     return PropertyIsLessThanOrEqualTo(**kwargs)