| 1 |
from .base import GEOSBase |
| 2 |
from .prototypes import prepared as capi |
| 3 |
|
| 4 |
|
| 5 |
class PreparedGeometry(GEOSBase): |
| 6 |
""" |
| 7 |
A geometry that is prepared for performing certain operations. |
| 8 |
At the moment this includes the contains covers, and intersects |
| 9 |
operations. |
| 10 |
""" |
| 11 |
|
| 12 |
ptr_type = capi.PREPGEOM_PTR |
| 13 |
destructor = capi.prepared_destroy |
| 14 |
|
| 15 |
def __init__(self, geom): |
| 16 |
# Keeping a reference to the original geometry object to prevent it |
| 17 |
# from being garbage collected which could then crash the prepared one |
| 18 |
# See #21662 |
| 19 |
self._base_geom = geom |
| 20 |
from .geometry import GEOSGeometry |
| 21 |
|
| 22 |
if not isinstance(geom, GEOSGeometry): |
| 23 |
raise TypeError |
| 24 |
self.ptr = capi.geos_prepare(geom.ptr) |
| 25 |
|
| 26 |
def contains(self, other): |
| 27 |
return capi.prepared_contains(self.ptr, other.ptr) |
| 28 |
|
| 29 |
def contains_properly(self, other): |
| 30 |
return capi.prepared_contains_properly(self.ptr, other.ptr) |
| 31 |
|
| 32 |
def covers(self, other): |
| 33 |
return capi.prepared_covers(self.ptr, other.ptr) |
| 34 |
|
| 35 |
def intersects(self, other): |
| 36 |
return capi.prepared_intersects(self.ptr, other.ptr) |
| 37 |
|
| 38 |
def crosses(self, other): |
| 39 |
return capi.prepared_crosses(self.ptr, other.ptr) |
| 40 |
|
| 41 |
def disjoint(self, other): |
| 42 |
return capi.prepared_disjoint(self.ptr, other.ptr) |
| 43 |
|
| 44 |
def overlaps(self, other): |
| 45 |
return capi.prepared_overlaps(self.ptr, other.ptr) |
| 46 |
|
| 47 |
def touches(self, other): |
| 48 |
return capi.prepared_touches(self.ptr, other.ptr) |
| 49 |
|
| 50 |
def within(self, other): |
| 51 |
return capi.prepared_within(self.ptr, other.ptr) |