Esempio n. 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
Esempio n. 2
0
    def get_filepaths(self, collection_id: str, spatial_extent: List[float],
                      temporal_extent: List[str]) -> List[str]:
        """Retrieve a file list from the a CSW server according to the specified parameters.

        Arguments:
            collecion_id {str} -- identifier of the collection
            spatial_extent {List[float]} -- bounding box [ymin, xmin, ymax, xmax]
            temporal_extent {List[str]} -- e.g. ["2018-06-04", "2018-06-23"]

        Returns:
            list -- list of filepaths
        """
        csw = CatalogueServiceWeb(self.csw_server_uri, timeout=300)

        constraints = []
        constraints.append(PropertyIsLike(self.group_property, collection_id))

        # Spatial filter
        constraints.append(BBox(spatial_extent))
        # Temporal filter
        constraints.append(
            PropertyIsGreaterThan('apiso:TempExtent_begin',
                                  temporal_extent[0]))
        constraints.append(
            PropertyIsLessThan('apiso:TempExtent_end', temporal_extent[1]))

        # Run the query
        csw.getrecords2(constraints=[constraints], maxrecords=100)

        # Put found records in a variable (dictionary)
        records0 = csw.records

        # Sort records
        records = []
        for record in records0:
            records.append(records0[record].references[0]['url'])
        records = sorted(records)

        return records
Esempio n. 3
0
 def filter_comp_less_than(self, **kwargs):
     return PropertyIsLessThan(**kwargs)