~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to django/contrib/gis/geos/coordseq.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.1.8 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090729112628-pg09ino8sz0sj21t
Tags: 1.1-1
* New upstream release.
* Merge from experimental:
  - Ship FastCGI initscript and /etc/default file in python-django's examples
    directory (Closes: #538863)
  - Drop "05_10539-sphinx06-compatibility.diff"; it has been applied
    upstream.
  - Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 LineString, and LinearRing geometries.
5
5
"""
6
6
from ctypes import c_double, c_uint, byref
7
 
from types import ListType, TupleType
 
7
from django.contrib.gis.geos.base import GEOSBase, numpy
8
8
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
9
 
from django.contrib.gis.geos.libgeos import CS_PTR, HAS_NUMPY
10
 
from django.contrib.gis.geos.prototypes import cs_clone, cs_getdims, cs_getordinate, cs_getsize, cs_setordinate
11
 
if HAS_NUMPY: from numpy import ndarray
 
9
from django.contrib.gis.geos.libgeos import CS_PTR
 
10
from django.contrib.gis.geos import prototypes as capi
12
11
 
13
 
class GEOSCoordSeq(object):
 
12
class GEOSCoordSeq(GEOSBase):
14
13
    "The internal representation of a list of coordinates inside a Geometry."
15
14
 
 
15
    ptr_type = CS_PTR
 
16
 
16
17
    #### Python 'magic' routines ####
17
18
    def __init__(self, ptr, z=False):
18
19
        "Initializes from a GEOS pointer."
44
45
    def __setitem__(self, index, value):
45
46
        "Sets the coordinate sequence value at the given index."
46
47
        # Checking the input value
47
 
        if isinstance(value, (ListType, TupleType)):
 
48
        if isinstance(value, (list, tuple)):
48
49
            pass
49
 
        elif HAS_NUMPY and isinstance(value, ndarray):
 
50
        elif numpy and isinstance(value, numpy.ndarray):
50
51
            pass
51
52
        else:
52
53
            raise TypeError('Must set coordinate with a sequence (list, tuple, or numpy array).')
76
77
        if dim < 0 or dim > 2:
77
78
            raise GEOSException('invalid ordinate dimension "%d"' % dim)
78
79
 
79
 
    @property
80
 
    def ptr(self):
81
 
        """
82
 
        Property for controlling access to coordinate sequence pointer,
83
 
        preventing attempted access to a NULL memory location.
84
 
        """
85
 
        if self._ptr: return self._ptr
86
 
        else: raise GEOSException('NULL coordinate sequence pointer encountered.')
87
 
 
88
80
    #### Ordinate getting and setting routines ####
89
81
    def getOrdinate(self, dimension, index):
90
82
        "Returns the value for the given dimension and index."
91
83
        self._checkindex(index)
92
84
        self._checkdim(dimension)
93
 
        return cs_getordinate(self.ptr, index, dimension, byref(c_double()))
 
85
        return capi.cs_getordinate(self.ptr, index, dimension, byref(c_double()))
94
86
 
95
87
    def setOrdinate(self, dimension, index, value):
96
88
        "Sets the value for the given dimension and index."
97
89
        self._checkindex(index)
98
90
        self._checkdim(dimension)
99
 
        cs_setordinate(self.ptr, index, dimension, value)
 
91
        capi.cs_setordinate(self.ptr, index, dimension, value)
100
92
 
101
93
    def getX(self, index):
102
94
        "Get the X value at the index."
126
118
    @property
127
119
    def size(self):
128
120
        "Returns the size of this coordinate sequence."
129
 
        return cs_getsize(self.ptr, byref(c_uint()))
 
121
        return capi.cs_getsize(self.ptr, byref(c_uint()))
130
122
 
131
123
    @property
132
124
    def dims(self):
133
125
        "Returns the dimensions of this coordinate sequence."
134
 
        return cs_getdims(self.ptr, byref(c_uint()))
 
126
        return capi.cs_getdims(self.ptr, byref(c_uint()))
135
127
 
136
128
    @property
137
129
    def hasz(self):
144
136
    ### Other Methods ###
145
137
    def clone(self):
146
138
        "Clones this coordinate sequence."
147
 
        return GEOSCoordSeq(cs_clone(self.ptr), self.hasz)
 
139
        return GEOSCoordSeq(capi.cs_clone(self.ptr), self.hasz)
148
140
 
149
141
    @property
150
142
    def kml(self):