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
def _get_input_files(self): """Download input files to local cache. Based on the product_site_code and product_variables attributes, query geoserver to find all public files relevant to the product, download them to the handler's temporary directory. Set the handler's input_file_variables attributes to a dict mapping file dest_path to a list of variables in the file. """ filter_list = [ PropertyIsEqualTo(propertyname='site_code', literal=self.product_site_code), PropertyIsEqualTo(propertyname='file_version', literal='1'), PropertyIsEqualTo(propertyname='realtime', literal='false'), PropertyIsNotEqualTo(propertyname='data_category', literal='Biogeochem_profiles'), PropertyIsNotEqualTo(propertyname='data_category', literal='CTD_profiles'), PropertyIsNotEqualTo(propertyname='data_category', literal='aggregated_timeseries') ] wfs_features = self.get_wfs_features(filter_list, propertyname=['url', 'variables']) if not wfs_features: raise MissingFileError( "No input files found for site '{self.product_site_code}'". format(self=self)) self.input_file_variables = { f['properties']['url']: f['properties']['variables'].split(', ') for f in wfs_features } self.input_file_collection = RemotePipelineFileCollection( self.input_file_variables.keys()) # Download input files to local cache. self.logger.info("Downloading {n} input files".format( n=len(self.input_file_collection))) self.input_file_collection.download(self._upload_store_runner.broker, self.temp_dir)
def filter_comp_not_equal_to(self, **kwargs): return PropertyIsNotEqualTo(**kwargs)