Django

Code

Changeset 7406

Show
Ignore:
Timestamp:
04/07/08 16:43:36 (5 months ago)
Author:
jbronn
Message:

gis: gdal: Added the clone keyword to OGRGeometry.transform; removed unnecessary __nonzero__ function from SpatialReference.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/geometries.py

    r7127 r7406  
    326326        geom_close_rings(self._ptr) 
    327327 
    328     def transform(self, coord_trans): 
    329         """ 
    330         Transforms this geometry to a different spatial reference system.  May take 
    331         either a CoordTransform object or a SpatialReference object. 
    332         """ 
     328    def transform(self, coord_trans, clone=False): 
     329        """ 
     330        Transforms this geometry to a different spatial reference system. 
     331        May take a CoordTransform object, a SpatialReference object, string 
     332        WKT or PROJ.4, and/or an integer SRID.  By default nothing is returned 
     333        and the geometry is transformed in-place.  However, if the `clone` 
     334        keyword is set, then a transformed clone of this geometry will be 
     335        returned. 
     336        """ 
     337        if clone: 
     338            klone = self.clone() 
     339            klone.transform(coord_trans) 
     340            return klone 
    333341        if isinstance(coord_trans, CoordTransform): 
    334342            geom_transform(self._ptr, coord_trans._ptr) 
     
    339347            geom_transform_to(self._ptr, sr._ptr) 
    340348        else: 
    341             raise TypeError('Either a CoordTransform or a SpatialReference object required for transformation.') 
     349            raise TypeError('Transform only accepts CoordTransform, SpatialReference, string, and integer objects.') 
    342350 
    343351    def transform_to(self, srs): 
     
    432440    def union(self, other): 
    433441        """ 
    434         Returns a new geometry consisting of the region which is the union of                                                                                                    
     442        Returns a new geometry consisting of the region which is the union of 
    435443        this geometry and the other. 
    436444        """ 
  • django/branches/gis/django/contrib/gis/gdal/srs.py

    r7102 r7406  
    140140            return self.attr_value(target) 
    141141 
    142     def __nonzero__(self): 
    143         "Returns True if this SpatialReference object is valid." 
    144         try: 
    145             self.validate() 
    146             return True 
    147         except OGRException: 
    148             return False 
    149  
    150142    def __str__(self): 
    151143        "The string representation uses 'pretty' WKT." 
  • django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py

    r7113 r7406  
    282282        t3.transform(ct) 
    283283 
    284         for p in (t1, t2, t3): 
    285             prec = 3 
     284        # Testing use of the `clone` keyword. 
     285        k1 = orig.clone() 
     286        k2 = k1.transform(trans.srid, clone=True) 
     287        self.assertEqual(k1, orig) 
     288        self.assertNotEqual(k1, k2) 
     289 
     290        prec = 3 
     291        for p in (t1, t2, t3, k2): 
    286292            self.assertAlmostEqual(trans.x, p.x, prec) 
    287293            self.assertAlmostEqual(trans.y, p.y, prec)