2013-12-24 23:53:09 +08:00
|
|
|
from .base import GEOSBase
|
|
|
|
from .prototypes import prepared as capi
|
Refactored the GEOS interface. Improvements include:
* Geometries now allow list-like manipulation, e.g., can add, insert, delete vertexes (or other geometries in collections) like Python lists. Thanks, Aryeh Leib Taurog.
* Added support for GEOS prepared geometries via `prepared` property. Prepared geometries significantly speed up certain operations.
* Added support for GEOS cascaded union as `MultiPolygon.cascaded_union` property.
* Added support for GEOS line merge as `merged` property on `LineString`, and `MultiLineString` geometries. Thanks, Paul Smith.
* No longer use the deprecated C API for serialization to/from WKB and WKT. Now use the GEOS I/O classes, which are now exposed as `WKTReader`, `WKTWriter`, `WKBReader`, and `WKBWriter` (which supports 3D and SRID inclusion)
* Moved each type of geometry to their own module, eliminating the cluttered `geometries.py`.
* Internally, all C API methods are explicitly called from a module rather than a star import.
Fixed #9557, #9877, #10222
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24 08:12:21 +08:00
|
|
|
|
2013-11-03 01:18:46 +08:00
|
|
|
|
Refactored the GEOS interface. Improvements include:
* Geometries now allow list-like manipulation, e.g., can add, insert, delete vertexes (or other geometries in collections) like Python lists. Thanks, Aryeh Leib Taurog.
* Added support for GEOS prepared geometries via `prepared` property. Prepared geometries significantly speed up certain operations.
* Added support for GEOS cascaded union as `MultiPolygon.cascaded_union` property.
* Added support for GEOS line merge as `merged` property on `LineString`, and `MultiLineString` geometries. Thanks, Paul Smith.
* No longer use the deprecated C API for serialization to/from WKB and WKT. Now use the GEOS I/O classes, which are now exposed as `WKTReader`, `WKTWriter`, `WKBReader`, and `WKBWriter` (which supports 3D and SRID inclusion)
* Moved each type of geometry to their own module, eliminating the cluttered `geometries.py`.
* Internally, all C API methods are explicitly called from a module rather than a star import.
Fixed #9557, #9877, #10222
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24 08:12:21 +08:00
|
|
|
class PreparedGeometry(GEOSBase):
|
|
|
|
"""
|
|
|
|
A geometry that is prepared for performing certain operations.
|
|
|
|
At the moment this includes the contains covers, and intersects
|
|
|
|
operations.
|
|
|
|
"""
|
|
|
|
ptr_type = capi.PREPGEOM_PTR
|
2016-12-16 05:59:08 +08:00
|
|
|
destructor = capi.prepared_destroy
|
Refactored the GEOS interface. Improvements include:
* Geometries now allow list-like manipulation, e.g., can add, insert, delete vertexes (or other geometries in collections) like Python lists. Thanks, Aryeh Leib Taurog.
* Added support for GEOS prepared geometries via `prepared` property. Prepared geometries significantly speed up certain operations.
* Added support for GEOS cascaded union as `MultiPolygon.cascaded_union` property.
* Added support for GEOS line merge as `merged` property on `LineString`, and `MultiLineString` geometries. Thanks, Paul Smith.
* No longer use the deprecated C API for serialization to/from WKB and WKT. Now use the GEOS I/O classes, which are now exposed as `WKTReader`, `WKTWriter`, `WKBReader`, and `WKBWriter` (which supports 3D and SRID inclusion)
* Moved each type of geometry to their own module, eliminating the cluttered `geometries.py`.
* Internally, all C API methods are explicitly called from a module rather than a star import.
Fixed #9557, #9877, #10222
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24 08:12:21 +08:00
|
|
|
|
|
|
|
def __init__(self, geom):
|
2013-12-24 22:19:25 +08:00
|
|
|
# Keeping a reference to the original geometry object to prevent it
|
|
|
|
# from being garbage collected which could then crash the prepared one
|
|
|
|
# See #21662
|
|
|
|
self._base_geom = geom
|
2015-04-25 00:09:20 +08:00
|
|
|
from .geometry import GEOSGeometry
|
2013-10-17 16:17:41 +08:00
|
|
|
if not isinstance(geom, GEOSGeometry):
|
|
|
|
raise TypeError
|
Refactored the GEOS interface. Improvements include:
* Geometries now allow list-like manipulation, e.g., can add, insert, delete vertexes (or other geometries in collections) like Python lists. Thanks, Aryeh Leib Taurog.
* Added support for GEOS prepared geometries via `prepared` property. Prepared geometries significantly speed up certain operations.
* Added support for GEOS cascaded union as `MultiPolygon.cascaded_union` property.
* Added support for GEOS line merge as `merged` property on `LineString`, and `MultiLineString` geometries. Thanks, Paul Smith.
* No longer use the deprecated C API for serialization to/from WKB and WKT. Now use the GEOS I/O classes, which are now exposed as `WKTReader`, `WKTWriter`, `WKBReader`, and `WKBWriter` (which supports 3D and SRID inclusion)
* Moved each type of geometry to their own module, eliminating the cluttered `geometries.py`.
* Internally, all C API methods are explicitly called from a module rather than a star import.
Fixed #9557, #9877, #10222
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24 08:12:21 +08:00
|
|
|
self.ptr = capi.geos_prepare(geom.ptr)
|
|
|
|
|
|
|
|
def contains(self, other):
|
|
|
|
return capi.prepared_contains(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def contains_properly(self, other):
|
|
|
|
return capi.prepared_contains_properly(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def covers(self, other):
|
|
|
|
return capi.prepared_covers(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def intersects(self, other):
|
|
|
|
return capi.prepared_intersects(self.ptr, other.ptr)
|
2013-12-24 23:53:09 +08:00
|
|
|
|
|
|
|
def crosses(self, other):
|
|
|
|
return capi.prepared_crosses(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def disjoint(self, other):
|
|
|
|
return capi.prepared_disjoint(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def overlaps(self, other):
|
|
|
|
return capi.prepared_overlaps(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def touches(self, other):
|
|
|
|
return capi.prepared_touches(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def within(self, other):
|
|
|
|
return capi.prepared_within(self.ptr, other.ptr)
|