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
|
|
|
# Copyright (c) 2008-2009 Aryeh Leib Taurog, all rights reserved.
|
|
|
|
# Released under the New BSD license.
|
|
|
|
"""
|
|
|
|
This module contains a base type which provides list-style mutations
|
2009-04-11 02:32:17 +08:00
|
|
|
without specific data storage methods.
|
|
|
|
|
|
|
|
See also http://www.aryehleib.com/MutableLists.html
|
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
|
|
|
|
|
|
|
Author: Aryeh Leib Taurog.
|
|
|
|
"""
|
|
|
|
class ListMixin(object):
|
|
|
|
"""
|
2009-04-11 02:32:17 +08:00
|
|
|
A base class which provides complete list interface.
|
|
|
|
Derived classes must call ListMixin's __init__() function
|
|
|
|
and implement the following:
|
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
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
function _get_single_external(self, i):
|
|
|
|
Return single item with index i for general use.
|
|
|
|
The index i will always satisfy 0 <= i < len(self).
|
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
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
function _get_single_internal(self, i):
|
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
|
|
|
Same as above, but for use within the class [Optional]
|
2009-04-11 02:32:17 +08:00
|
|
|
Note that if _get_single_internal and _get_single_internal return
|
|
|
|
different types of objects, _set_list must distinguish
|
|
|
|
between the two and handle each appropriately.
|
|
|
|
|
|
|
|
function _set_list(self, length, items):
|
|
|
|
Recreate the entire object.
|
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
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
NOTE: items may be a generator which calls _get_single_internal.
|
|
|
|
Therefore, it is necessary to cache the values in a temporary:
|
|
|
|
temp = list(items)
|
|
|
|
before clobbering the original storage.
|
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
|
|
|
|
|
|
|
function _set_single(self, i, value):
|
|
|
|
Set the single item at index i to value [Optional]
|
|
|
|
If left undefined, all mutations will result in rebuilding
|
2009-04-11 02:32:17 +08:00
|
|
|
the object using _set_list.
|
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
|
|
|
|
|
|
|
function __len__(self):
|
|
|
|
Return the length
|
|
|
|
|
|
|
|
int _minlength:
|
|
|
|
The minimum legal length [Optional]
|
|
|
|
|
|
|
|
int _maxlength:
|
|
|
|
The maximum legal length [Optional]
|
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
type or tuple _allowed:
|
|
|
|
A type or tuple of allowed item types [Optional]
|
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 _IndexError:
|
|
|
|
The type of exception to be raise on invalid index [Optional]
|
|
|
|
"""
|
|
|
|
|
|
|
|
_minlength = 0
|
|
|
|
_maxlength = None
|
|
|
|
_IndexError = IndexError
|
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
### Python initialization and special list interface methods ###
|
2009-03-26 10:07:11 +08:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2009-04-11 02:32:17 +08:00
|
|
|
if not hasattr(self, '_get_single_internal'):
|
|
|
|
self._get_single_internal = self._get_single_external
|
2009-03-26 10:07:11 +08:00
|
|
|
|
|
|
|
if not hasattr(self, '_set_single'):
|
|
|
|
self._set_single = self._set_single_rebuild
|
|
|
|
self._assign_extended_slice = self._assign_extended_slice_rebuild
|
|
|
|
|
|
|
|
super(ListMixin, self).__init__(*args, **kwargs)
|
|
|
|
|
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 __getitem__(self, index):
|
2009-04-11 02:32:17 +08:00
|
|
|
"Get the item(s) at the specified index/slice."
|
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
|
|
|
if isinstance(index, slice):
|
2009-04-11 02:32:17 +08:00
|
|
|
return [self._get_single_external(i) for i in xrange(*index.indices(len(self)))]
|
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
|
|
|
else:
|
|
|
|
index = self._checkindex(index)
|
2009-04-11 02:32:17 +08:00
|
|
|
return self._get_single_external(index)
|
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 __delitem__(self, index):
|
2009-04-11 02:32:17 +08:00
|
|
|
"Delete the item(s) at the specified index/slice."
|
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
|
|
|
if not isinstance(index, (int, long, slice)):
|
|
|
|
raise TypeError("%s is not a legal index" % index)
|
|
|
|
|
|
|
|
# calculate new length and dimensions
|
|
|
|
origLen = len(self)
|
|
|
|
if isinstance(index, (int, long)):
|
|
|
|
index = self._checkindex(index)
|
|
|
|
indexRange = [index]
|
|
|
|
else:
|
|
|
|
indexRange = range(*index.indices(origLen))
|
|
|
|
|
|
|
|
newLen = origLen - len(indexRange)
|
2009-04-11 02:32:17 +08:00
|
|
|
newItems = ( self._get_single_internal(i)
|
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
|
|
|
for i in xrange(origLen)
|
|
|
|
if i not in indexRange )
|
|
|
|
|
|
|
|
self._rebuild(newLen, newItems)
|
|
|
|
|
|
|
|
def __setitem__(self, index, val):
|
2009-04-11 02:32:17 +08:00
|
|
|
"Set the item(s) at the specified index/slice."
|
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
|
|
|
if isinstance(index, slice):
|
|
|
|
self._set_slice(index, val)
|
|
|
|
else:
|
|
|
|
index = self._checkindex(index)
|
|
|
|
self._check_allowed((val,))
|
|
|
|
self._set_single(index, val)
|
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
def __iter__(self):
|
|
|
|
"Iterate over the items in the list"
|
|
|
|
for i in xrange(len(self)):
|
|
|
|
yield self[i]
|
|
|
|
|
|
|
|
### Special methods for arithmetic operations ###
|
|
|
|
def __add__(self, other):
|
|
|
|
'add another list-like object'
|
|
|
|
return self.__class__(list(self) + list(other))
|
|
|
|
|
|
|
|
def __radd__(self, other):
|
|
|
|
'add to another list-like object'
|
|
|
|
return other.__class__(list(other) + list(self))
|
|
|
|
|
|
|
|
def __iadd__(self, other):
|
|
|
|
'add another list-like object to self'
|
|
|
|
self.extend(list(other))
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __mul__(self, n):
|
|
|
|
'multiply'
|
|
|
|
return self.__class__(list(self) * n)
|
|
|
|
|
|
|
|
def __rmul__(self, n):
|
|
|
|
'multiply'
|
|
|
|
return self.__class__(list(self) * n)
|
|
|
|
|
|
|
|
def __imul__(self, n):
|
|
|
|
'multiply'
|
|
|
|
if n <= 0:
|
|
|
|
del self[:]
|
|
|
|
else:
|
|
|
|
cache = list(self)
|
|
|
|
for i in range(n-1):
|
|
|
|
self.extend(cache)
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __cmp__(self, other):
|
|
|
|
'cmp'
|
|
|
|
slen = len(self)
|
|
|
|
for i in range(slen):
|
|
|
|
try:
|
|
|
|
c = cmp(self[i], other[i])
|
|
|
|
except IndexError:
|
|
|
|
# must be other is shorter
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
# elements not equal
|
|
|
|
if c: return c
|
|
|
|
|
|
|
|
return cmp(slen, len(other))
|
|
|
|
|
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
|
|
|
### Public list interface Methods ###
|
2009-04-11 02:32:17 +08:00
|
|
|
## Non-mutating ##
|
|
|
|
def count(self, val):
|
|
|
|
"Standard list count method"
|
|
|
|
count = 0
|
|
|
|
for i in self:
|
|
|
|
if val == i: count += 1
|
|
|
|
return count
|
|
|
|
|
|
|
|
def index(self, val):
|
|
|
|
"Standard list index method"
|
|
|
|
for i in xrange(0, len(self)):
|
|
|
|
if self[i] == val: return i
|
|
|
|
raise ValueError('%s not found in object' % str(val))
|
|
|
|
|
|
|
|
## Mutating ##
|
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 append(self, val):
|
|
|
|
"Standard list append method"
|
|
|
|
self[len(self):] = [val]
|
|
|
|
|
|
|
|
def extend(self, vals):
|
|
|
|
"Standard list extend method"
|
|
|
|
self[len(self):] = vals
|
|
|
|
|
|
|
|
def insert(self, index, val):
|
|
|
|
"Standard list insert method"
|
|
|
|
if not isinstance(index, (int, long)):
|
|
|
|
raise TypeError("%s is not a legal index" % index)
|
|
|
|
self[index:index] = [val]
|
|
|
|
|
|
|
|
def pop(self, index=-1):
|
|
|
|
"Standard list pop method"
|
|
|
|
result = self[index]
|
|
|
|
del self[index]
|
|
|
|
return result
|
|
|
|
|
|
|
|
def remove(self, val):
|
|
|
|
"Standard list remove method"
|
|
|
|
del self[self.index(val)]
|
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
def reverse(self):
|
|
|
|
"Standard list reverse method"
|
|
|
|
self[:] = self[-1::-1]
|
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
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
def sort(self, cmp=cmp, key=None, reverse=False):
|
|
|
|
"Standard list sort method"
|
|
|
|
if key:
|
|
|
|
temp = [(key(v),v) for v in self]
|
|
|
|
temp.sort(cmp=cmp, key=lambda x: x[0], reverse=reverse)
|
|
|
|
self[:] = [v[1] for v in temp]
|
|
|
|
else:
|
|
|
|
temp = list(self)
|
|
|
|
temp.sort(cmp=cmp, reverse=reverse)
|
|
|
|
self[:] = temp
|
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
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
### Private routines ###
|
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 _rebuild(self, newLen, newItems):
|
|
|
|
if newLen < self._minlength:
|
|
|
|
raise ValueError('Must have at least %d items' % self._minlength)
|
|
|
|
if self._maxlength is not None and newLen > self._maxlength:
|
|
|
|
raise ValueError('Cannot have more than %d items' % self._maxlength)
|
|
|
|
|
2009-04-11 02:32:17 +08:00
|
|
|
self._set_list(newLen, newItems)
|
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 _set_single_rebuild(self, index, value):
|
|
|
|
self._set_slice(slice(index, index + 1, 1), [value])
|
|
|
|
|
|
|
|
def _checkindex(self, index, correct=True):
|
|
|
|
length = len(self)
|
|
|
|
if 0 <= index < length:
|
|
|
|
return index
|
|
|
|
if correct and -length <= index < 0:
|
|
|
|
return index + length
|
|
|
|
raise self._IndexError('invalid index: %s' % str(index))
|
|
|
|
|
|
|
|
def _check_allowed(self, items):
|
|
|
|
if hasattr(self, '_allowed'):
|
|
|
|
if False in [isinstance(val, self._allowed) for val in items]:
|
|
|
|
raise TypeError('Invalid type encountered in the arguments.')
|
|
|
|
|
|
|
|
def _set_slice(self, index, values):
|
|
|
|
"Assign values to a slice of the object"
|
|
|
|
try:
|
|
|
|
iter(values)
|
|
|
|
except TypeError:
|
|
|
|
raise TypeError('can only assign an iterable to a slice')
|
|
|
|
|
|
|
|
self._check_allowed(values)
|
|
|
|
|
|
|
|
origLen = len(self)
|
|
|
|
valueList = list(values)
|
|
|
|
start, stop, step = index.indices(origLen)
|
|
|
|
|
|
|
|
# CAREFUL: index.step and step are not the same!
|
|
|
|
# step will never be None
|
|
|
|
if index.step is None:
|
|
|
|
self._assign_simple_slice(start, stop, valueList)
|
|
|
|
else:
|
|
|
|
self._assign_extended_slice(start, stop, step, valueList)
|
|
|
|
|
|
|
|
def _assign_extended_slice_rebuild(self, start, stop, step, valueList):
|
|
|
|
'Assign an extended slice by rebuilding entire list'
|
|
|
|
indexList = range(start, stop, step)
|
|
|
|
# extended slice, only allow assigning slice of same size
|
|
|
|
if len(valueList) != len(indexList):
|
|
|
|
raise ValueError('attempt to assign sequence of size %d '
|
|
|
|
'to extended slice of size %d'
|
|
|
|
% (len(valueList), len(indexList)))
|
|
|
|
|
|
|
|
# we're not changing the length of the sequence
|
|
|
|
newLen = len(self)
|
|
|
|
newVals = dict(zip(indexList, valueList))
|
|
|
|
def newItems():
|
|
|
|
for i in xrange(newLen):
|
|
|
|
if i in newVals:
|
|
|
|
yield newVals[i]
|
|
|
|
else:
|
2009-04-11 02:32:17 +08:00
|
|
|
yield self._get_single_internal(i)
|
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._rebuild(newLen, newItems())
|
|
|
|
|
|
|
|
def _assign_extended_slice(self, start, stop, step, valueList):
|
|
|
|
'Assign an extended slice by re-assigning individual items'
|
|
|
|
indexList = range(start, stop, step)
|
|
|
|
# extended slice, only allow assigning slice of same size
|
|
|
|
if len(valueList) != len(indexList):
|
|
|
|
raise ValueError('attempt to assign sequence of size %d '
|
|
|
|
'to extended slice of size %d'
|
|
|
|
% (len(valueList), len(indexList)))
|
|
|
|
|
|
|
|
for i, val in zip(indexList, valueList):
|
|
|
|
self._set_single(i, val)
|
|
|
|
|
|
|
|
def _assign_simple_slice(self, start, stop, valueList):
|
|
|
|
'Assign a simple slice; Can assign slice of any length'
|
|
|
|
origLen = len(self)
|
|
|
|
stop = max(start, stop)
|
|
|
|
newLen = origLen - stop + start + len(valueList)
|
|
|
|
def newItems():
|
|
|
|
for i in xrange(origLen + 1):
|
|
|
|
if i == start:
|
|
|
|
for val in valueList:
|
|
|
|
yield val
|
|
|
|
|
|
|
|
if i < origLen:
|
|
|
|
if i < start or i >= stop:
|
2009-04-11 02:32:17 +08:00
|
|
|
yield self._get_single_internal(i)
|
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._rebuild(newLen, newItems())
|