/usr/lib/python3/dist-packages/shapely/iterops.py is in python3-shapely 1.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 | """
Iterative forms of operations
"""
from warnings import warn
from ctypes import c_char_p, c_size_t
from shapely.geos import lgeos, PredicateError
def geos_from_geometry(geom):
warn("`geos_from_geometry` is deprecated. Use geometry's `wkb` property "
"instead.", DeprecationWarning)
data = geom.to_wkb()
return lgeos.GEOSGeomFromWKB_buf(
c_char_p(data),
c_size_t(len(data))
)
class IterOp(object):
"""A generating non-data descriptor.
"""
def __init__(self, fn):
self.fn = fn
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")
retval = self.fn(context._geom, this_geom._geom)
if retval == 2:
raise PredicateError(
"Failed to evaluate %s" % repr(self.fn))
elif bool(retval) == value:
yield ob
# utilities
disjoint = IterOp(lgeos.GEOSDisjoint)
touches = IterOp(lgeos.GEOSTouches)
intersects = IterOp(lgeos.GEOSIntersects)
crosses = IterOp(lgeos.GEOSCrosses)
within = IterOp(lgeos.GEOSWithin)
contains = IterOp(lgeos.GEOSContains)
overlaps = IterOp(lgeos.GEOSOverlaps)
equals = IterOp(lgeos.GEOSEquals)
|