Coverage for gws-app/gws/plugin/ows_server/csw/filter.py: 0%
37 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1import gws
2import gws.gis.crs
3import gws.gis.extent
4import gws.gis.bounds
7class Filter:
8 def __init__(self, index):
9 self.index = index
11 def apply(self, flt, recs):
12 fn = getattr(self, '_' + flt.name.lower(), None)
13 if not fn:
14 return []
15 return fn(flt, recs)
17 def _and(self, flt, recs):
18 for el in flt.all():
19 recs = self.apply(el, recs)
20 return recs
22 def _or(self, flt, recs):
23 ns = set()
24 for el in flt.all():
25 ns.update(r.index for r in self.apply(el, recs))
26 return [r for r in recs if r.index in ns]
28 def _bbox(self, flt, recs):
29 b = gws.gis.bounds.from_gml_envelope_element(flt.first('Envelope'))
30 if not b:
31 return []
32 b = gws.gis.bounds.transformed_to(b, gws.gis.crs.get4326())
33 return [
34 r for r in recs
35 if not r.get('wgsExtent') or gws.gis.extent.intersect(r.wgsExtent, b.extent)
36 ]
38 def _propertyislike(self, flt, recs):
39 # @TODO wildcards
41 try:
42 prop = (flt.first('propertyname').text or 'csw:AnyText').lower()
43 val = flt.first('literal').text
44 except TypeError:
45 return []
47 if prop == 'csw:anytext':
48 ns = set(
49 idx for f, s, lows, idx in self.index
50 if val in s
51 )
52 else:
53 ns = set(
54 idx for p, s, lows, idx in self.index
55 if val in s and p == prop
56 )
58 return [r for r in recs if r.index in ns]