File: iterops.py

package info (click to toggle)
python-shapely 1.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,368 kB
  • sloc: python: 9,915; makefile: 102; sh: 31
file content (41 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Iterative forms of operations
"""

from shapely.geos import PredicateError
from shapely.topology import Delegating


class IterOp(Delegating):

    """A generating non-data descriptor.
    """

    def __call__(self, context, iterator, value=True):
        if context._geom is None:
            raise ValueError("Null geometry supports no operations")
        for item in iterator:
            try:
                this_geom, ob = item
            except TypeError:
                this_geom = item
                ob = this_geom
            if not this_geom._geom:
                raise ValueError("Null geometry supports no operations")
            try:
                retval = self.fn(context._geom, this_geom._geom)
            except Exception as err:
                self._check_topology(err, context, this_geom)
            if bool(retval) == value:
                yield ob


# utilities
disjoint = IterOp('disjoint')
touches = IterOp('touches')
intersects = IterOp('intersects')
crosses = IterOp('crosses')
within = IterOp('within')
contains = IterOp('contains')
overlaps = IterOp('overlaps')
equals = IterOp('equals')