/usr/share/pyshared/shapely/prepared.py is in python-shapely 1.2.14-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 55 56 57 58 59 60 | """
Support for GEOS prepared geometry operations.
"""
from shapely.geos import lgeos
from shapely.impl import DefaultImplementation, delegated
class PreparedGeometry(object):
"""
A geometry prepared for efficient comparison to a set of other geometries.
Example:
>>> from shapely.geometry import Point, Polygon
>>> triangle = Polygon(((0.0, 0.0), (1.0, 1.0), (1.0, -1.0)))
>>> p = prep(triangle)
>>> p.intersects(Point(0.5, 0.5))
True
"""
impl = DefaultImplementation
def __init__(self, context):
self.context = context
self.__geom__ = lgeos.GEOSPrepare(self.context._geom)
def __del__(self):
if self.__geom__ is not None:
try:
lgeos.GEOSPreparedGeom_destroy(self.__geom__)
except AttributeError:
pass # lgeos might be empty on shutdown
self.__geom__ = None
self.context = None
@property
def _geom(self):
return self.__geom__
@delegated
def intersects(self, other):
return bool(self.impl['prepared_intersects'](self, other))
@delegated
def contains(self, other):
return bool(self.impl['prepared_contains'](self, other))
@delegated
def contains_properly(self, other):
return bool(self.impl['prepared_contains_properly'](self, other))
@delegated
def covers(self, other):
return bool(self.impl['prepared_covers'](self, other))
def prep(ob):
"""Creates and returns a prepared geometric object."""
return PreparedGeometry(ob)
|