2013-12-24 23:53:09 +08:00
|
|
|
from .base import GEOSBase
|
2013-12-25 00:35:13 +08:00
|
|
|
from .error import GEOSException
|
2013-12-24 23:53:09 +08:00
|
|
|
from .geometry import GEOSGeometry
|
|
|
|
from .libgeos import geos_version_info
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
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 __del__(self):
|
2014-09-13 02:45:59 +08:00
|
|
|
if self._ptr and capi:
|
2013-10-17 16:17:41 +08:00
|
|
|
capi.prepared_destroy(self._ptr)
|
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 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
|
|
|
|
|
|
|
# Added in GEOS 3.3:
|
|
|
|
|
|
|
|
def crosses(self, other):
|
|
|
|
if geos_version_info()['version'] < '3.3.0':
|
|
|
|
raise GEOSException("crosses on prepared geometries requires GEOS >= 3.3.0")
|
|
|
|
return capi.prepared_crosses(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def disjoint(self, other):
|
|
|
|
if geos_version_info()['version'] < '3.3.0':
|
|
|
|
raise GEOSException("disjoint on prepared geometries requires GEOS >= 3.3.0")
|
|
|
|
return capi.prepared_disjoint(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def overlaps(self, other):
|
|
|
|
if geos_version_info()['version'] < '3.3.0':
|
|
|
|
raise GEOSException("overlaps on prepared geometries requires GEOS >= 3.3.0")
|
|
|
|
return capi.prepared_overlaps(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def touches(self, other):
|
|
|
|
if geos_version_info()['version'] < '3.3.0':
|
|
|
|
raise GEOSException("touches on prepared geometries requires GEOS >= 3.3.0")
|
|
|
|
return capi.prepared_touches(self.ptr, other.ptr)
|
|
|
|
|
|
|
|
def within(self, other):
|
|
|
|
if geos_version_info()['version'] < '3.3.0':
|
|
|
|
raise GEOSException("within on prepared geometries requires GEOS >= 3.3.0")
|
|
|
|
return capi.prepared_within(self.ptr, other.ptr)
|