@@ -41,8 +41,7 @@ def datetime_filter(date_filter: str):
4141 dt_filter = {
4242 "type" : "DateRangeFilter" ,
4343 "field_name" : "acquired" ,
44- "config" : {
45- },
44+ "config" : {},
4645 }
4746
4847 if start_date :
@@ -54,6 +53,27 @@ def datetime_filter(date_filter: str):
5453
5554
5655def comparison_filter (comp_filter ):
56+ if comp_filter ["args" ][0 ]["property" ] == "datetime" :
57+ dt_filter = {
58+ "type" : "DateRangeFilter" ,
59+ "field_name" : "acquired" ,
60+ "config" : {},
61+ }
62+
63+ if comp_filter ["op" ] == ">" :
64+ dt_filter ["config" ]["gt" ] = comp_filter ["args" ][1 ]
65+
66+ if comp_filter ["op" ] == ">=" :
67+ dt_filter ["config" ]["gte" ] = comp_filter ["args" ][1 ]
68+
69+ if comp_filter ["op" ] == "<" :
70+ dt_filter ["config" ]["lt" ] = comp_filter ["args" ][1 ]
71+
72+ if comp_filter ["op" ] == "<=" :
73+ dt_filter ["config" ]["lte" ] = comp_filter ["args" ][1 ]
74+
75+ return dt_filter
76+
5777 return {
5878 "type" : "RangeFilter" ,
5979 "field_name" : comp_filter ["args" ][0 ]["property" ].lstrip ("properties." ),
@@ -69,7 +89,7 @@ def geometry_filter(geometry_filter):
6989 "field_name" : geometry_filter ["args" ][0 ]["property" ].lstrip ("properties." ),
7090 "config" : {
7191 "type" : "Polygon" ,
72- "coordinates" : geometry_filter ["args" ][1 ]["coordinates" ]
92+ "coordinates" : geometry_filter ["args" ][1 ]["coordinates" ],
7393 },
7494 }
7595
@@ -80,7 +100,9 @@ def convert_filter(stac_filter: dict):
80100 for sub_filter in stac_filter ["args" ]:
81101 config .append (convert_filter (sub_filter ))
82102
83- config = [c for c in config if c is not None ] # if there are any unrecognised filters then ignore them instead of erroring
103+ config = [
104+ c for c in config if c is not None
105+ ] # if there are any unrecognised filters then ignore them instead of erroring
84106 return {"type" : f"{ stac_filter ['op' ].title ()} Filter" , "config" : config }
85107
86108 elif stac_filter ["op" ] in ["<" , ">" , "<=" , ">=" ]:
@@ -115,10 +137,7 @@ def build_search_filter(stac_request):
115137 {
116138 "type" : "GeometryFilter" ,
117139 "field_name" : "geometry" ,
118- "config" : {
119- "type" : "Polygon" ,
120- "coordinates" : bbox_to_intersects (bbox )
121- },
140+ "config" : {"type" : "Polygon" , "coordinates" : bbox_to_intersects (bbox )},
122141 }
123142 )
124143
0 commit comments