EOX GitLab Instance

utils.py 528 Bytes
Newer Older
Nikola Jankovic's avatar
Nikola Jankovic committed
1
from typing import List
Nikola Jankovic's avatar
Nikola Jankovic committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

from pygeofilter.backends.native.evaluate import NativeEvaluator
from pygeofilter.parsers.cql_json import parse as json_parse


def cql_filter(_filter: dict, data: List[dict]) -> List[dict]:
    if not _filter:
        return data
    _filter = json_parse(_filter)
    attr_map = {"point_attr": "geometry", "*": "properties.*"}
    nat_eval = NativeEvaluator(attribute_map=attr_map, use_getattr=False)
    evaluator = nat_eval.evaluate(_filter)
    data = list(filter(evaluator, data))

    return data