EOX GitLab Instance

utils.py 915 Bytes
Newer Older
1
2
import importlib
from typing import Any, Iterator
3

Nikola Jankovic's avatar
Nikola Jankovic committed
4
5
6
7
from pygeofilter.backends.native.evaluate import NativeEvaluator
from pygeofilter.parsers.cql_json import parse as json_parse


8
def cql_filter(_filter: dict, data: Iterator[dict]) -> Iterator[dict]:
Nikola Jankovic's avatar
Nikola Jankovic committed
9
    if not _filter:
10
11
        yield from data
        return
Nikola Jankovic's avatar
Nikola Jankovic committed
12
13
14
15
    _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)
16
    yield from filter(evaluator, data)
17
18
19
20
21
22
23
24
25
26
27


def import_by_path(path: str) -> Any:
    """Imports the object from the referenced module.

    Args:
        path (str): the dotted Python path, where the last element is the
        object in the referenced module.
    """
    module_path, _, object_name = path.rpartition(".")
    return getattr(importlib.import_module(module_path), object_name)