|
0
|
1 |
from django.contrib.gis.geos.base import GEOSBase |
|
|
2 |
from django.contrib.gis.geos.geometry import GEOSGeometry |
|
|
3 |
from django.contrib.gis.geos.prototypes import prepared as capi |
|
|
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 |
ptr_type = capi.PREPGEOM_PTR |
|
|
12 |
|
|
|
13 |
def __init__(self, geom): |
|
|
14 |
if not isinstance(geom, GEOSGeometry): raise TypeError |
|
|
15 |
self.ptr = capi.geos_prepare(geom.ptr) |
|
|
16 |
|
|
|
17 |
def __del__(self): |
|
|
18 |
if self._ptr: capi.prepared_destroy(self._ptr) |
|
|
19 |
|
|
|
20 |
def contains(self, other): |
|
|
21 |
return capi.prepared_contains(self.ptr, other.ptr) |
|
|
22 |
|
|
|
23 |
def contains_properly(self, other): |
|
|
24 |
return capi.prepared_contains_properly(self.ptr, other.ptr) |
|
|
25 |
|
|
|
26 |
def covers(self, other): |
|
|
27 |
return capi.prepared_covers(self.ptr, other.ptr) |
|
|
28 |
|
|
|
29 |
def intersects(self, other): |
|
|
30 |
return capi.prepared_intersects(self.ptr, other.ptr) |