Changeset 1043

Show
Ignore:
Timestamp:
02/07/08 21:02:31
Author:
seang
Message:

Rename coordinate accessors to _get/_set and cripple the ones of classes that are not direct coordinate sequence containers. Provide a method to update the data of a coordinate sequence.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Shapely/trunk/shapely/geometry/base.py

    r1005 r1043  
    4848 
    4949class CoordinateSequence(object): 
    50  
     50     
     51    _geom = None 
    5152    _cseq = None 
    5253    _ndim = None 
     
    5556 
    5657    def __init__(self, geom): 
    57         self._cseq = lgeos.GEOSGeom_getCoordSeq(geom._geom) 
     58        self._geom = geom._geom 
    5859        self._ndim = geom._ndim 
    59  
     60        self.update_cseq() 
     61 
     62    def update_cseq(self): 
     63        self._cseq = lgeos.GEOSGeom_getCoordSeq(self._geom) 
     64         
    6065    def __iter__(self): 
    6166        self.index = 0 
     67        self.update_cseq() 
    6268        self._length = self.__len__() 
    6369        return self 
     
    8793     
    8894    def __getitem__(self, i): 
     95        self.update_cseq() 
    8996        M = self.__len__() 
    9097        if i + M < 0 or i >= M: 
     
    219226    # in __geom so that geometries and geometry adapters can share __del__ 
    220227 
    221     def get_geom(self): 
     228    def _get_geom(self): 
    222229        return self.__geom 
    223     def set_geom(self, val): 
     230 
     231    def _set_geom(self, val): 
    224232        self.__geom = val 
    225     _geom = property(get_geom, set_geom) 
     233     
     234    _geom = property(_get_geom, _set_geom) 
    226235 
    227236    # Array and ctypes interfaces 
     
    254263 
    255264    @exceptNull 
    256     def get_coords(self): 
     265    def _get_coords(self): 
    257266        return CoordinateSequence(self) 
    258267 
    259     def set_coords(self, ob): 
     268    def _set_coords(self, ob): 
    260269        raise NotImplementedError, \ 
    261270            "set_coords must be provided by derived classes" 
    262271 
    263     coords = property(get_coords, set_coords) 
     272    coords = property(_get_coords, _set_coords) 
    264273 
    265274    # Python feature protocol 
  • Shapely/trunk/shapely/geometry/linestring.py

    r1006 r1043  
    167167    # Coordinate access 
    168168 
    169     def set_coords(self, coordinates): 
     169    def _set_coords(self, coordinates): 
    170170        if self._geom is None: 
    171171            self._init_geom(coordinates) 
    172172        update_linestring_from_py(self, coordinates) 
    173173 
    174     coords = property(BaseGeometry.get_coords, set_coords) 
     174    coords = property(BaseGeometry._get_coords, _set_coords) 
    175175 
    176176 
     
    216216            return self.array_interface() 
    217217 
    218     coords = property(BaseGeometry.get_coords) 
     218    _get_coords = BaseGeometry._get_coords 
     219 
     220    def _set_coords(self, ob): 
     221        raise NotImplementedError, \ 
     222        "Component rings have coordinate sequences, but the polygon does not" 
     223 
     224    coords = property(_get_coords) 
    219225 
    220226 
  • Shapely/trunk/shapely/geometry/multilinestring.py

    r1005 r1043  
    9797        "Multi-part geometries do not themselves provide the array interface" 
    9898 
     99    def _get_coords(self): 
     100        raise NotImplementedError, \ 
     101        "Component rings have coordinate sequences, but the polygon does not" 
     102 
     103    def _set_coords(self, ob): 
     104        raise NotImplementedError, \ 
     105        "Component rings have coordinate sequences, but the polygon does not" 
     106 
    99107    @property 
    100108    def coords(self): 
  • Shapely/trunk/shapely/geometry/multipoint.py

    r1005 r1043  
    119119    __array_interface__ = property(array_interface) 
    120120 
     121    def _get_coords(self): 
     122        raise NotImplementedError, \ 
     123        "Component rings have coordinate sequences, but the polygon does not" 
     124 
     125    def _set_coords(self, ob): 
     126        raise NotImplementedError, \ 
     127        "Component rings have coordinate sequences, but the polygon does not" 
     128 
    121129    @property 
    122130    def coords(self): 
  • Shapely/trunk/shapely/geometry/multipolygon.py

    r1005 r1043  
    8383        "Multi-part geometries do not themselves provide the array interface" 
    8484 
     85    def _get_coords(self): 
     86        raise NotImplementedError, \ 
     87        "Component rings have coordinate sequences, but the polygon does not" 
     88 
     89    def _set_coords(self, ob): 
     90        raise NotImplementedError, \ 
     91        "Component rings have coordinate sequences, but the polygon does not" 
     92 
    8593    @property 
    8694    def coords(self): 
  • Shapely/trunk/shapely/geometry/point.py

    r1006 r1043  
    191191    # Coordinate access 
    192192 
    193     def set_coords(self, coordinates): 
     193    def _set_coords(self, coordinates): 
    194194        if self._geom is None: 
    195195            self._init_geom(coordinates) 
     
    197197            update_point_from_py(self, coordinates) 
    198198 
    199     coords = property(BaseGeometry.get_coords, set_coords) 
     199    coords = property(BaseGeometry._get_coords, _set_coords) 
    200200 
    201201 
     
    242242            return self.array_interface() 
    243243 
    244     coords = property(BaseGeometry.get_coords) 
     244    _get_coords = BaseGeometry._get_coords 
     245 
     246    def _set_coords(self, ob): 
     247        raise NotImplementedError, \ 
     248        "Component rings have coordinate sequences, but the polygon does not" 
     249 
     250    coords = property(_get_coords) 
    245251 
    246252 
  • Shapely/trunk/shapely/geometry/polygon.py

    r1006 r1043  
    183183    # Coordinate access 
    184184 
    185     def set_coords(self, coordinates): 
     185    _get_coords = BaseGeometry._get_coords 
     186 
     187    def _set_coords(self, coordinates): 
    186188        if self._geom is None: 
    187189            self._init_geom(coordinates) 
    188190        update_linearring_from_py(self, coordinates) 
    189191 
    190     coords = property(BaseGeometry.get_coords, set_coords) 
     192    coords = property(_get_coords, _set_coords) 
    191193 
    192194 
     
    212214            } 
    213215 
    214     coords = property(BaseGeometry.get_coords) 
     216    coords = property(BaseGeometry._get_coords) 
    215217 
    216218 
     
    364366        "A polygon does not itself provide the array interface. Its rings do." 
    365367 
     368    def _get_coords(self): 
     369        raise NotImplementedError, \ 
     370        "Component rings have coordinate sequences, but the polygon does not" 
     371 
     372    def _set_coords(self, ob): 
     373        raise NotImplementedError, \ 
     374        "Component rings have coordinate sequences, but the polygon does not" 
     375 
    366376    @property 
    367377    def coords(self): 
  • Shapely/trunk/tests/Polygon.txt

    r1006 r1043  
    8989  IndexError: index out of range 
    9090 
     91Coordinate getters and setters raise exceptions 
     92 
     93  >>> polygon._get_coords() 
     94  Traceback (most recent call last): 
     95  ... 
     96  NotImplementedError: Component rings have coordinate sequences, but the polygon does not 
     97  >>> polygon.coords 
     98  Traceback (most recent call last): 
     99  ... 
     100  NotImplementedError: Component rings have coordinate sequences, but the polygon does not 
     101 
    91102 
    92103Geo interface 
     
    129140  3.414... 
    130141 
     142 
  • Shapely/trunk/tests/test_doctests.py

    r963 r1043  
    3131 
    3232if __name__ == "__main__": 
    33     runner = unittest.TextTestRunner(
     33    runner = unittest.TextTestRunner(verbosity=1
    3434    runner.run(test_suite())